I am making a function that gives the players money depending if they won or not but it is not working (UNSOV)

I am making a PVP survival game and depending If the player won the round or not then they get awarded “Money” and I am coding the part where when the player dies then they only get 5 “Money” but if they win then they get 10 “Money” But It is not working for some reason I can’t figure out is instead of the player getting 5 “Money” they get a lot more than what I wanted them to get here is my code:

Server Script

game:GetService('ReplicatedStorage'):WaitForChild('Events'):WaitForChild('RemoteEvents'):WaitForChild("GameEvents"):WaitForChild('Give5Money').OnServerEvent:Connect(function(player)
		task.wait(3)
		local money = player:WaitForChild('leaderstats'):WaitForChild('Money')
		print("MONEY VALUE BEFORE: " .. money.Value)
		money.Value = money.Value + 1.5
		print("MONEY VALUE AFTER: " .. money.Value)
	end)

I am using 1.5 “Money” because when I tested it at the end of the round I got 8.5 “Money” when I only wanted it to give 5 and nothing more here is my local script code:

Local Script

if survived.Value == false then
		moneyEarned.Value = 5
		amountEarnedText.Text = "You Earned $"..moneyEarned.Value.."!"
		game:GetService('ReplicatedStorage'):WaitForChild('Events'):WaitForChild('RemoteEvents'):WaitForChild("GameEvents"):WaitForChild('Give5Money'):FireServer(game.Players.LocalPlayer)
	end

Thanks.

2 Likes

Probably you have code that is making the same event connection several times. Why do you have an event called “Give5Money”. Shouldn’t that be a function that takes a value specifying how much money? Then you dont need multiple events for that.

1 Like

Aqjanna is right, you could just use a RemoteEvent and like
Local:
game:GetService('ReplicatedStorage'):WaitForChild('Events'):WaitForChild('RemoteEvents'):WaitForChild("GameEvents").PrizeMoney:FireServer(moneyEarned.Value)

Server:

game:GetService('ReplicatedStorage'):WaitForChild('Events'):WaitForChild('RemoteEvents'):WaitForChild("GameEvents").PrizeMoney.OnServerEvent:Connect(function(player, PRIZE)

1 Like

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