onPlayerJoin Script Repeating Upon Death of Character(s)

Hello Developers!
I am currently finding a few issues with join messages.
If you know a way I can Modify the scripts to not repeat on player death, please tell me.
The Messages Repeat Upon Player Death(s)

Server Join Message Script Issue; When a player dies, the message system responds back in the chat with the history of players that joined after you, every single player name is said again.

onPlayerJoin Script:

local players = game.Players
local gui = game.StarterGui

function onPlayerAdded(player)
	gui:SetCore("ChatMakeSystemMessage", {
		Text = ("[Server]: " ..player.DisplayName.. " has joined the experience");
		Color = Color3.fromRGB(85, 0, 127);
		Font = Enum.Font.SourceSansBold;
		FontSize = Enum.FontSize.Size18;
	})
end

players.PlayerAdded:Connect(onPlayerAdded)

for _,player in pairs(players:GetPlayers()) do
	onPlayerAdded(player)
end

At the function onPlayerAdded you forgot parenthesis.

1.) Where is this script located in the hierarchy of your game?
2.) Why are you looping through every player and running the join message? If you only want it displayed on player join you don’t need to do that.

Do you mean here? If so I just tested it and that disabled the entire script.

Is this somewhere in starter player? If it is then when a player dies the script will be recreated again and this might cause it to run every time they die.

1.) The script is located under StarterGui of the game.
2.) I didn’t mean for it to loop it, that’s the issue.

I think also there too. If it’s a function, it must end with (). Every function ends in ().

The script is probably resetting every time the player respawns which causes the for loop to run after each death

That’s what I had guessed, but I’m unsure of how to stop that from being the case.

Is this script a LocalScript or ServerScript?

Is it inside of a gui? if it is turn off the reset on spawn property

It’s a LocalScript, does that change something?

You don’t need a () here since you’re just passing the function object into Connect rather than actually calling it.

The StarterGui clones everything inside it into a player’s PlayerGui whenever their character is added. Maybe change the parent of the script to StarterPlayerScripts.

Try putting the code into a ServerScript in ServerScriptService.

Putting it into StarterPlayerScripts worked, thank you!

1 Like

Thank you for telling me! I never knew.