我刚浏览一个脚本,却遇到一个错误,我真的不知道如何解决。如果有人可以帮忙,我将不胜感激! (第15行,尝试以'CharacterAdded'错误为索引nil。)
local TweenService = game:GetService("TweenService")
local blurDelay = 0 --seconds
local blurDuration = 6 --seconds
local blurEffect = Instance.new("BlurEffect")
blurEffect.Size = 0
blurEffect.Enabled = false
blurEffect.Parent = game.Workspace.CurrentCamera
local tween
local function createTween()
local tweenInfo = TweenInfo.new(blurDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, blurDelay)
return TweenService:Create(blurEffect, tweenInfo, {Size = 56})
end
game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
if tween and tween.PlaybackState == Enum.PlaybackState.Playing then
tween:Cancel()
end
blurEffect.Size = 0
blurEffect.Enabled = false
humanoid.Died:Connect(function()
blurEffect.Enabled = true
tween = createTween()
tween:Play()
end)
end)
编辑:
答案 0 :(得分:1)
您收到此错误,因为如果将此代码放入服务器上的常规Script中,则没有LocalPlayer。您需要在LocalScript中运行它,并将其放入StarterPlayerScripts。完全可以满足您的要求。
答案 1 :(得分:0)
不是game.Players.LocalPlayer.PlayerAdded
,请改用game.Players.PlayerAdded
。