Why is it not adding points?

This script is supposed to add points on the event and have them get multiplied by the value of the rebirth multiplier but it doesn’t add any points at all. It was working before I added the rebirth multiplier so I think it could be the way I defined the multiplier variable because I’m not totally sure how to define things that are in StarterPlayerScripts. It doesn’t give me any errors in the output so I’m not sure what’s wrong.

game.ReplicatedStorage.Remotes.Add.OnServerEvent:Connect(function(player)
	if not debounce then
		debounce = true
		local currency = 'Points'
		local multiplier = player:WaitForChild("PlayerScripts").Rebirth.Multiplier
		local ammount = math.random(2,4) * multiplier.Value
		player.leaderstats[currency].Value = player.leaderstats[currency].Value + ammount
	wait(0.5)
		debounce = false
		end

end)

game.ReplicatedStorage.Remotes.Add.OnServerEvent:Connect(function(player)
	if not debounce then
		debounce == true
		local currency = 'Points'
		local multiplier = player:WaitForChild("PlayerScripts").Rebirth.Multiplier
		local ammount = math.random(2,4) * multiplier.Value
		player.leaderstats.currency.Value = player.leaderstats.currency.Value + ammount
	wait(0.5)
		debounce == false
		end

end)

The problem isn’t in the currency variable it’s in either the multiplier variable or the amount variable where I multiplied it by the multiplier value.

Is your event being fired at all? Try adding a breakpoint right at if not debounce then and press play. (to add breakpoint, click next to line number)

Also note when setting debounce to true or false, make sure to use one equals sign.
This checks to see if debounce is false: (Not intended)
debounce == false
This sets debounce to false: (Intended)
debounce = false

1 Like

Yes, the event is firing, I had it fire in another script.

PlayerScripts can only be accessed from a LocalScript.
OnServerInvoke can only be connected from a (server) Script.

Is this in a LocalScript or a (server) Script?

You use one equal sign when you are defining a variable. When you are changing a boolean in a function from false to true or true to false, you use two of them.

It’s a server script. How would I access the multiplier if I can’t get to it from a script?

1 Like

Ah, well when you call :WaitForChild("PlayerScripts") it hangs, because PlayerScripts is only accessible from the client (localscript).

Should I just move the multiplier somewhere else and move it into the player via a leaderstat?

Just a heads up, an exploiter can run this to get infinite rebirths in your game:

while true do
	game.ReplicatedStorage.Remotes.Add:FireServer()
	task.wait()
end

because you are breaking the golden rule: Never Trust the Client.

1 Like

You should:

  1. Move rebirths to the Player itself (not in PlayerScripts) and from the server.
  2. Check to see if the player has enough to rebirth on the server, not the client.

The rebirths are in the player the rebirth I referenced in the script is the name of the script the multiplier is in.

Makes sense. But still, the Rebirth script is in PlayerScripts, which is inaccessible to the server.

Can you show us the code in Rebirth? (So that we may move the functionality to the server)

local player = game.Players.LocalPlayer
local rebirths = player:WaitForChild("leaderstats").Rebirths
local multiplier = script.Multiplier
rebirths.Changed:Connect(function()
	if rebirths.Value >1 then
		multiplier.Value = multiplier.Value * 2
	end
end)

Cant you move this code to the server?
If you can, it will make what you want to do possible.

Instead of waiting for PlayerScripts, store the Multiplier value directly into the player.

Make Rebirths a server script, create a multiplier value in each player, and keep everyrhing else the same.

Also, make sure leaderstats is being changed on the server, not the client.