Duplicating messages?!

Hello guys.
I made a lua which show message when player join the server.
But when player join it paste message to chat twice or more times

This looks like:

Player has joined the server
Player has joined the server
Player has joined the server

This is my shared lua:



hook.Add("PlayerConnect", "PlayerConnect", function( name )   
    for k,v in pairs(player.GetAll()) do
        v:ChatPrint( "Player " .. name .. " has joined the server")
    end
end)


Please help to fix it.

make it server side only



hook.Add("PlayerConnect", "PlayerConnect", function( name )	
		v:ChatPrint( "Player " .. name .. " has joined the server")
end)


Work ? :smiley:

[lua]
hook.Add(“PlayerConnect”, “PlayerConnect”, function(name)
if (CLIENT) then
LocalPlayer():ChatPrint(“Player “…name…” has joined the server.”);
end;
end);
[/lua]

Also use [.lua][/lua] tags.

That’ll not work since it’s serverside but…

[lua]
hook.Add(“PlayerConnect”, “PlayerConnect”, function(name)
PrintMessage( HUD_PRINTTALK, “Player “…name…” has joined the server.”)
//PrintMessage( HUD_PRINTTALK, “”) // Prints to everyone once
end);
[/lua]

There’s a reason the above posters are calling that argument “name”.

Fixed I re looked at it you’re right.

Won’t work cause you removed the loop and you are calling ChatPrint on a nil variable (v).

Will it show to everybody on server?

Yep the new code I posted

[lua]hook.Add(“PlayerConnect”, “PlayerConnect”, function(name)
PrintMessage( HUD_PRINTTALK, “Player “…tostring(name)…” has joined the server.”) // Prints to everyone once
end)[/lua]

Is this what you want?

[lua]
hook.Add(“PlayerInitialSpawn”, “PISMessage”, function(ply)
for k, v in pairs(player.GetAll()) do
if v != ply then
v:PrintMessage(HUD_PRINTTALK, “Player “…ply:Name()…” has joined the game!”)
else
v:PrintMessage(HUD_PRINTTALK, “Welcome, “…ply:Name()…”!”)
end
end
end)
[/lua]
Output:



Player Dylan has joined the game!


Output if the joining player is YOU:




Welcome, Dylan!


Don’t use dylanb5123 code he’s probably a kid and a newbie coder, it’ll just duplicate for when people join.

I honestly hope you’re kidding…

Shhh… don’t hurt his feelings… I think he’s… special…

Oops, lol, i have failed, sorry :stuck_out_tongue: