Answered by
7 years ago Edited 7 years ago
The reason that your script broke is that player is not a parameter to the RobloxScriptSignal [event] MouseButton1Click
. If this is in a local script, which it should be, because all scripts that work in the PlayerGui, or StarterGui must be LocalScripts due to FilteringEnabled then you would try this method:
1 | local player = game.Players.LocalPlayer |
2 | script.Parent.MouseButton 1 Click:connect( function () |
3 | local lstats = player:WaitForChild( 'leaderstats' ) |
4 | if lstats.Tokens.Value > = 60 then |
5 | lstats.Tokens.Value = lstats.Tokens.Value - 60 |
7 | script.Parent.Text = 'Insufficient Funds!' |
But that probably won't work online because of FIltering Enabled. Your best bet is to use this method of using RemoteFunctions
This is how to use the recommended method
Step 1: put a RemoteFunction in the ReplicatedStorage named HandleTransaction
Step 2: Put these in your game
Replace your script with this LocalScript and put it in the same place.
1 | local player = game.Players.LocalPlayer |
2 | local rf = game.ReplicatedStorage:WaitForChild( "HandleTransaction" ) |
4 | script.Parent.MouseButton 1 Click:Connect( function () |
5 | local transaction = rf:InvokeServer() |
6 | if not transaction then |
7 | script.Parent.Text = 'Insufficient Funds!' |
Insert a Script inside the ServerScriptStorage
01 | local rf = game.ReplicatedStorage:WaitForChild( "HandleTransaction" ) |
03 | function re.OnServerInvoke(player) |
04 | if player:FindFirstChild( "leaderstats" ) and player.leaderstats:FindFirstChild( "Tokens" ) |
06 | if player.leaderstats.Tokens.Value > = 60 then |
07 | player.leaderstats.Tokens.Value = player.leaderstats.Tokens.Value - 60 |