Why is this script being repeated when more than 1 player joins the game?

I’m pretty sure this script is the one repeating multiple times as players get 2 wins and then like 8 wins then 11 for no reason (the amount is random but it appears to be giving players around 1-10 wins per round)

Dead = false
plr = game.Players.PlayerAdded:Connect(function(plr)
	print("Starting the death penalty thing")

		local Char = plr.Character
		if Char == nil then
			until Char ~= nil
		Dead = true

		if Dead == false then
			print("Plr survived")
			plr.leaderstats.Survivals.Value = plr.leaderstats.Survivals.Value + 1
			plr.leaderstats.Grub.Value = plr.leaderstats.Grub.Value + 10
			print("Player Died")
			Dead = false

how is this happening? (this script is a server script in serverscriptservice)

You wrapped it in a PlayerAdded event. So everytime someone joins the game, it’ll run.

would i have to make this a local script? i tried to avoid doing that to prevent exploiters from changing the values or is there another way?

No, don’t make it a local script.

Look into the events: RemoteEvent | Roblox Creator Documentation
The player instance is passed through an event. So that’s how you can get your player variable.

1 Like

Alright, i’ll try this out! i’ll return if it fails

And if you’re using a BindableEvent, look into this: Events | Roblox Creator Documentation

from what i’ve tested it seems to work perfectly. i’m assuming the issue is resolved since i tested it multiple times. thank you for your help!

1 Like