![](/img/trans.png)
[英]i have this issue "Workspace.hugyuihjoih.LocalScript:4: attempt to index nil with 'Destroy'"
[英]Workspace.Arrow.StandGiver:38: attempt to index nil with 'Destroy'
我的目標是,當您單擊箭頭時,Players 中的文件夾而不是 Stand1 應該更改為 Stand2,但這不會發生。 試圖解決,但沒有任何幫助。
此行中的錯誤:
上一篇:Destroy()
local Arrow = script.Parent
local Click = Arrow:WaitForChild("Click")
Click.MouseClick:Connect(function(player)
local Backpack = player:FindFirstChild("Backpack")
if Backpack then
local Stands = game:GetService("ServerStorage"):WaitForChild("Stands")
local PlrStats = player:WaitForChild("PlrStats")
local currentStand = PlrStats:WaitForChild("Stand")
local randomStand = math.random(1,2)
if randomStand == 1 then
--Give Stand1
if Backpack:FindFirstChild("Stand1") or Backpack:FindFirstChild("Stand2") then
local prevStand = workspace:FindFirstChild(player.Name.." Stand")
local prev = Backpack:FindFirstChild("Stand1") or Backpack:FindFirstChild("Stand2")
prevStand:Destroy()
prev:Destroy()
local Stand = Stands:FindFirstChild("Stand1"):Clone()
Stand.Parent = Backpack
currentStand.Value = "Stand1"
else
local Stand = Stands:FindFirstChild("Stand1"):Clone()
Stand.Parent = Backpack
currentStand.Value = "Stand1"
end
elseif randomStand == 2 then
--Give Stand2
if Backpack:FindFirstChild("Stand1") or Backpack:FindFirstChild("Stand2") then
local prevStand = workspace:FindFirstChild(player.Name.."Stand")
local prev = Backpack:FindFirstChild("Stand1") or Backpack:FindFirstChild("Stand2")
prevStand:Destroy()
prev:Destroy()
local Stand = Stands:FindFirstChild("Stand2"):Clone()
Stand.Parent = Backpack
currentStand.Value = "Stand2"
else
local Stand = Stands:FindFirstChild("Stand2"):Clone()
Stand.Parent = Backpack
currentStand.Value = "Stand2"
end
end
Arrow:Destroy()
end
end)
我有 Stand1 和 Stand2 的文件夾,我知道如何解決這個問題。
那么如果prevStand
為 nil, workspace:FindFirstChild(player.Name.."Stand")
顯然返回 nil。
如果沒有具有該名稱的子節點,或者如果該實例尚未復制,則在本地腳本中會發生這種情況。
嘗試改用WaitForChild 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.