Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

1

so you put a server script in the player's PlayerGui??

1

...tbh unsatisfie_d literally answered your question, you may wanna read up on the different between client and server.

1 answer

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.