我在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-堆栈结束
任何帮助都会很棒!如果您需要我对任何事情都更加具体,请告诉我!
这里是模型的链接
[tool
是nil
。
找出原因,并且只有在工具为有效值时才调用tool:Clone()
。