在roblox中使用商店GUI时遇到错误

我在roblox中使用这个商店GUI时遇到了一个错误,每当我尝试购买物品时都会出错。我已经提供了模型链接,您可以查看并尝试解决问题。这是代码出错的地方

local price = script.Parent.Parent.Price
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = tools:FindFirstChild(script.Parent.Parent.ItemName.Value)
local player = script.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:connect(function()
    if player.leaderstats:FindFirstChild("Coins").Value >= price.Value then -- 将“Money”更改为您的货币名称。例如:现金
        player.leaderstats:FindFirstChild("Coins").Value = player.leaderstats:FindFirstChild("Coins").Value - price.Value
        local clone = tool:Clone()
        clone.Parent = player.Backpack
        -- 如果您希望玩家即使死亡也保留该工具,请复制此代码
        local clone2 = tool:Clone()
        clone2.Parent = player.StarterGear
    end
end)

它给我的错误是这样的

10:16:49.715 - Players.kaitheawsomecathoo1.PlayerGui.Shop.Frame.Info.Buy.Script:9: attempt to index nil with 'Clone' 10:16:49.715 - Stack Begin 10:16:49.715 - Script 'Players.kaitheawsomecathoo1.PlayerGui.Shop.Frame.Info.Buy.Script', Line 9 10:16:49.716 - Stack End

任何帮助都会很棒!如果您需要更具体的信息,请告诉我!

这是模型的链接

https://www.roblox.com/library/1855829220/Shop-Gui-2018

点赞
用户2858170
用户2858170

toolnil

找出原因,仅在 tool 为有效值时调用 tool:Clone()

2020-04-17 15:30:52