在roblox中使用商店GUI出错

问题描述 投票:0回答:1

我在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 -- Change "Money" to the name of your currency. Example: Cash
        player.leaderstats:FindFirstChild("Coins").Value = player.leaderstats:FindFirstChild("Coins").Value - price.Value
        local clone = tool:Clone()
        clone.Parent = player.Backpack
        -- Copy this code if you want the player to still have the tool even if he died
        local clone2 = tool:Clone()
        clone2.Parent = player.StarterGear
    end
end)

这是它给我的错误。

10:16:49.715-Players.kaitheawsomecathoo1.PlayerGui.Shop.Frame.Info.Buy.Script:9:尝试使用“克隆”索引零10:16:49.715-堆栈开始10:16:49.715-脚本'Players.kaitheawsomecathoo1.PlayerGui.Shop.Frame.Info.Buy.Script',第9行10:16:49.716-堆栈结束

任何帮助都会很棒!如果您需要我对任何事情都更加具体,请告诉我!

这里是模型的链接

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

lua roblox
1个回答
1
投票

[toolnil

找出原因,并且只有在工具为有效值时才调用tool:Clone()

© www.soinside.com 2019 - 2024. All rights reserved.