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
5 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

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

Script that is Child of PlayerGui

local remote = game.ReplicatedStorage:WaitForChild('Subtract')

remote.OnServerEvent:Connect(function(player)
    print('Subtracting')
    local cost = script.Parent:WaitForChild('Weapon Shop').Frame.Frame.Cost.Text
    print('You had '..player.leaderstats.SeerBux.Value)
    player.leaderstats.SeerBux.Value = player.leaderstats.SeerBux.Value - tonumber(cost)
    print('You now have '..player.leaderstats.SeerBux.Value)
    print(cost..' was Subtracted')
    print('Subtract Successful')
end)

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

local but = script.Parent
plr = game.Players.LocalPlayer
local bag = plr:WaitForChild('Backpack')
local tool
local price
local bux
local tog = game.ReplicatedStorage:WaitForChild('Subtract')

but.MouseButton1Click:Connect(function()
    print('function start :)')
    price = but.Parent.Cost.Text
    price = tonumber(price)
    tool = but.Parent.ItemName.Text
    bux = plr.leaderstats.SeerBux.Value
    if bux >= price then
        print('Buying... :)')
        print('That costs '..price)
        print('You had '..bux)
        tog:FireServer()
        print('You now have '..bux)
        local Tool = game.ReplicatedStorage.Tool:WaitForChild(tool)
        if Tool then
            print('Tool Found :)')
            local ToolGive = Tool:Clone()
            ToolGive.Parent = bag
        else
            print('Tool Not Located :(')
        end
    else
        print('Not Enough Money :(')
        print('You Need '..price)
    end
end)
1
so you put a server script in the player's PlayerGui?? hellmatic 1523 — 5y
1
...tbh unsatisfie_d literally answered your question, you may wanna read up on the different between client and server. Mr_Pure 129 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

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

Answer this question