Currency System Error

Hello! I’m just trying out some things with scripting, as I’m fairly new to it. I tried making a button that, when clicked, would take away some of the player’s currency. However, I keep getting this error in the output:

BuyPet - Roblox Studio 8_12_2020 12_12_28 AM

The currency is an IntValue named “Tickets”, and is located directly inside of the player. I’m using a server script, which is located inside of a TextButton. Here’s the code that’s causing the error:

script.Parent.MouseButton1Down:Connect(function(player)
    local tickets = player.Tickets
    if tickets.Value >= 125 then
        tickets.Value = tickets.Value - 125
    end
end)

Thanks! :happy1:

You cannot use server scripts on gui elements, you would need to use a local script and fire a remote event to the server to do the action.

3 Likes

MouseButton1Click’s arguments are where the player clicked, not a player. (cjjdawg’s solution is right, this is just to clarify why the error is what it is.)

3 Likes

Hey, simple fix to add on to @cjjdawg’s solution.

You can use a localscript instead of a script.

And also, if you’re using a TextButton as the button to click, you’d want to use “MouseButton1Click:Connect” instead of “MouseButton1Down:Connect” I believe.

Thanks! I’ll be sure to use MouseButton1Click.

Also, the reason why I used a server script was because I needed to get other objects that couldn’t be accessed with a LocalScript. The RemoteEvent idea that @cjjdawg mentioned solved it.

1 Like

Ah okay, I didn’t know that. You have a great week!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.