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)
You need to have an equal to change the values so it would be:
player.leaderstats.SeerBux.Value = player.leaderstats.SeerBux.Value - tonumber(cost)