Money not subtracting despite having all the reasons to do so

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m making a shop for my game

  2. What is the issue? Include screenshots / videos if possible!
    The values don’t change. I tried doing it on the localscript and it only changed on the client but not the server, then I tried on the server script and it doesn’t even change at all

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked at every similar topic and it seems to work fine for them so I don’t know the problem.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Localscript:

local leaderstats = game:GetService("Players").LocalPlayer:WaitForChild("leaderstats")
local Currency = leaderstats:FindFirstChild("Noobcoins") -- Change the "YourCurrency" with the currency you made! In our case is Money
local dude = game.Players.LocalPlayer
local char = dude.Character

script.Parent.Activated:Connect(function()
	if Currency.value>9 and workspace.Allies.Value<60 then
		dude.leaderstats.Noobcoins.Value = dude.leaderstats.Noobcoins.Value - 10
		script.Summon:FireServer(dude,10)
	elseif workspace.Allies.Value == 60 then
		script.Parent.Parent.Parent.NoWarning:Play()
		script.Parent.Parent.Parent.Frame.Warning.Visible = true
		wait(2)
		script.Parent.Parent.Parent.Frame.Warning.Visible = false
	end
end)

The script inside the Summon remote event:

local char = game.ServerStorage.AntiNooby.Noob

script.Parent.OnServerEvent:Connect(function(player,cost)
	local coins = player.leaderstats.Noobcoins.Value
	coins = coins - cost
	workspace.Allies.Value = workspace.Allies.Value + 1
	local copy = char:Clone()
	copy.Parent = workspace
	copy:MoveTo(Vector3.new(math.random(-210,700), 80, math.random(-281,281)))
end)

I need an answer fast because I want to release this update before halloween.

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You’re getting the value of the NumberValue, i.e. a number. When you subtract from the value of coins, it will only change the variable you’ve created, not the value of the NumberValue. Change it to the following:

local coins = player.leaderstats.Noobcoins
coins.Value = coins.Value - cost

Also note that by allowing the client to tell the server what the cost is, and not checking that whatsoever on the server, an exploiter can give their own value and get free money.
Summon:FireServer(-99999999999999999) -- Free money for the exploiter!

  • Hard-code the cost into the server script and do not allow the client to provide it.

Performing the checks on the client is good, as that prevents the client from firing the remote only to find out that it does not have enough money; however, by skipping a check on the server, an exploiter can fire the remote even if they don’t have enough money, and the server will be none the wiser.

  • Keep the check on the client but add a second on the server

There isn’t a need to changing the value on the client, as any change that happens on the server will be replicated to the client. Simply fire the event let the server handle it.

Finally, just a tip: instead of writing longVaraibleName = longVariableName - number, you can write longVariableName -= number. This works exactly the same, only saving time. This also works for division, multiplication, addition, and modulus.

2 Likes

Nice job! Worked flawlessly first try. Now I just need to replicate this to all my 13 other shop options. Thanks in advance!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.