本文介绍了Roblox-尝试使用"leaderstats"索引零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何解决运行脚本时出现的错误吗?谢谢
Can someone tell me how can I fix this error that shows up when I run my script? Thanks
line 4: Workspace.Slide1.PointsPart.Script:4: attempt to index nil with 'leaderstats'
script.Parent.Touched:Connect(function(hit)
local player = hit.Parent:FindFirstChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.leaderstats.Points.Value >= 0 then
wait()
script.Disabled = true
script.Parent.Transparency = 1
script.Parent.CanCollide = false
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +5
wait(0.5)
script.Parent.Transparency = 1
script.Parent.CanCollide = false
script.Disabled = false
end
end)
推荐答案
Touched事件会触发任何与零件接触的事件.您不会处理零件不是玩家角色的孩子的情况.
The Touched event fires for anything that touches the part. You are not handling the case that a part isn't a child of a Player's Character.
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if not plr then
return
end
if plr.leaderstats.Points.Value >= 0 then
这篇关于Roblox-尝试使用"leaderstats"索引零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!