Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

(Surface GUI) What is going wrong, if the script has no errors?

Asked by 8 years ago
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.Text = tostring(script.Parent.ItemName.Value)..": "..tonumber(script.Parent.Cost.Value).." "..tostring(script.Parent.Currency.Value)
script.Parent.MouseButton1Click:connect(function()
    local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(Player.Name)
    -- STOPS HERE
    if cashmoney ~= nil then
        if cashmoney.Value >= script.Parent.Cost.Value then
            cashmoney.Value = cashmoney.Value - script.Parent.Cost.Value
            game.Lighting.Shop.Swords[script.Parent.ItemName.Value]:Clone().Parent = Player.Backpack
            game.Lighting.Shop.Swords[script.Parent.ItemName.Value]:Clone().Parent = Player.StarterGear
        end
    end
end)

The script is a "purchase" script inside of a Surface GUI on a brick. I have tried printing a number every single line, the script appears to stop just before if cashmoney ~= nil then, although cashmoney is present.

0
Your script might not work in online modes (even fixing your current problem) -- this script looks like a LocalScript (based on the player being an ancestor of the script), but clients don't get access to ServerStorage. If your script is a normal/server Script, then no problem. chess123mate 5873 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

Try doing this:

local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(Player.Name)

It could be because cashmoney is returning nil, due to the fact that the script couldn't locate it fast enough.

0
Note that if a child doesn't appear with the proper name, the script will never return from the WaitForChild function. Fortunately, I don't think the script needs to do anything else (based on what's posted), so that might be okay. On the other hand, the event only happens on MouseButton1Click, so that's plenty of time for the object to be created - there must be a different problem! chess123mate 5873 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

It's actually impossible for your script to stop where you specified - I think what actually happens is that cashmoney ~= nil is false, and so nothing else runs. This can easily happen if there is no child named the same as Player.Name in MoneyStorage. To check this, print out the relevant values on line 6:

print("Cashmoney:", cashmoney) --if it just prints out "Cashmoney:", that means it's nil
print(Player.Name)
print(game.ServerStorage.MoneyStorage:FindFirstChild(Player.Name))

Answer this question