Roblox Studio错误:ServerScriptService.Script:15:尝试使用'CharacterAdded'为nil索引 [英] Roblox Studio error: ServerScriptService.Script:15: attempt to index nil with 'CharacterAdded'
本文介绍了Roblox Studio错误:ServerScriptService.Script:15:尝试使用'CharacterAdded'为nil索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚浏览了一个脚本,却遇到了一个我不知道如何解决的错误.如果有人可以帮忙,我将不胜感激!(第15行,尝试使用"CharacterAdded"错误将索引索引为nil.)
I was just going over a script and I ran into an error I don't really know how to fix. If anybody can help I'd appreciate it! (Line 15,attempt to index nil with 'CharacterAdded' error.)
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)
- 我尝试将其切换为本地脚本",而不仅仅是脚本"仍然不起作用.我试图将其从ServerScriptService切换到StarterGUI
推荐答案
您会收到此错误,因为如果将此代码放入服务器上的常规脚本中,则不会有LocalPlayer.您需要在LocalScript中运行它,并将其放入StarterPlayerScripts.就像您所拥有的一样,它将正常工作.
You are getting the error, because if you put this code into a regular Script on the server, there is no LocalPlayer. You need to run it in a LocalScript and put that into StarterPlayerScripts. That will work just fine, exactly as you have it.
这篇关于Roblox Studio错误:ServerScriptService.Script:15:尝试使用'CharacterAdded'为nil索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文