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

I can't Subtract money from player's currency?

Asked by
sheepposu 561 Moderation Voter
6 years ago

I have a shop and these scripts. My problem is the money won't subtract. The event I have setup is not firing which is the main problem. If there is a way easier way, someone plz tell me. There are no errors in the output.

Script in ServerScriptService

1local remote1 = Instance.new('RemoteEvent')
2remote1.Name = 'Subtract'
3remote1.Parent = game:GetService('ReplicatedStorage')

Script that is Child of PlayerGui

01local remote = game.ReplicatedStorage:WaitForChild('Subtract')
02 
03remote.OnServerEvent:Connect(function(player)
04    print('Subtracting')
05    local cost = script.Parent:WaitForChild('Weapon Shop').Frame.Frame.Cost.Text
06    print('You had '..player.leaderstats.SeerBux.Value)
07    player.leaderstats.SeerBux.Value = player.leaderstats.SeerBux.Value - tonumber(cost)
08    print('You now have '..player.leaderstats.SeerBux.Value)
09    print(cost..' was Subtracted')
10    print('Subtract Successful')
11end)

Local Script under buy button (Inside a GUI); lines 7 & 19 are what fire the server when the button is clicked

01local but = script.Parent
02plr = game.Players.LocalPlayer
03local bag = plr:WaitForChild('Backpack')
04local tool
05local price
06local bux
07local tog = game.ReplicatedStorage:WaitForChild('Subtract')
08 
09but.MouseButton1Click:Connect(function()
10    print('function start :)')
11    price = but.Parent.Cost.Text
12    price = tonumber(price)
13    tool = but.Parent.ItemName.Text
14    bux = plr.leaderstats.SeerBux.Value
15    if bux >= price then
View all 33 lines...
1
so you put a server script in the player's PlayerGui?? hellmatic 1523 — 6y
1
...tbh unsatisfie_d literally answered your question, you may wanna read up on the different between client and server. Mr_Pure 129 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You need to have an equal to change the values so it would be:

1player.leaderstats.SeerBux.Value = player.leaderstats.SeerBux.Value - tonumber(cost)
Ad

Answer this question