Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Basic buying system script not working?

I'm making some basic buying system. But it's not working as it supposed to. When the button is clicked the text doesn't change into "Bought" or "Not Enough Money"

local script:

local a = script.aValue
local b = script.Cost --100

script.Parent.MouseButton1Click:Connect(function()
        if a.Value >= b then
               a.Value = a.Value - b
               script.Parent.Parent.Lbl.Text = "Bought"
               print("Success")
               script.Parent.Parent.Lbl.Text = b
        else
               script.Parent.Parent.Lbl.Text = "Not Enough Money"
               print("Failure")
               script.Parent.Parent.Lbl.Text = b
        end
end)

1 answer

✓ Accepted answer

The issue is that you're not getting the value from Cost

local a = script.aValue
local b = script.Cost --100

script.Parent.MouseButton1Click:Connect(function()
        if a.Value >= b.Value then
               a.Value = a.Value - b.Value
               script.Parent.Parent.Lbl.Text = "Bought"
               print("Success")
               script.Parent.Parent.Lbl.Text = b.Value
        else
               script.Parent.Parent.Lbl.Text = "Not Enough Money"
               print("Failure")
               script.Parent.Parent.Lbl.Text = b.Value
        end
end)

1 comment

1

Also you might want to add a delay between line 7 and 9 otherwise the text will only change for a very short time... Insert wait(2) between printing success and the next line :)

This discussion is preserved as it was. New answers, comments, and votes are closed.