【问题标题】:Getting an error with a shop GUI in robloxroblox 中的商店 GUI 出现错误
【发布时间】:2020-07-31 03:59:34
【问题描述】:

我在 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:尝试使用“克隆”索引 nil 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】:

    toolnil

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

    【讨论】:

    • 工具不是有效的工具。那么每次我想要不同的工具时,我是否需要调用不同的工具?
    • tool 是一个 nil 值,您必须在索引之前检查它是否为 nil
    猜你喜欢
    • 2018-12-17
    • 2020-03-28
    • 2020-10-25
    • 2020-08-05
    • 2017-02-20
    • 2015-08-11
    • 1970-01-01
    • 2016-11-12
    • 1970-01-01
    相关资源
    最近更新 更多