Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

PlayerAdded event doesn't work?

Hello,

I try to use this script. It has to print when someone joins/leaves the game, however I keep recieving this error. Can someone help me?

The script:


local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(player)
	print(player.Name + " joined the game!")
end)
 
Players.PlayerRemoving:Connect(function(player)
	print(player.Name + " left the game!")
end)

Error: 17:58:17.367 - Workspace.PlayerAddedEvents:4: attempt to perform arithmetic on field 'Name' (a string value)

2 answers

✓ Accepted answer

The issue is that on line 4 and 8 you are using "+" to connect two strings together and that's not how strings work. What you are looking for is "..", which is called concatenate, and that connects two strings together. for example print ("hello " .. "ok") would print out " hello ok".

Fixed Code

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
print(player.Name .. " joined the game!")
end)

Players.PlayerRemoving:Connect(function(player)
print(player.Name .. " left the game!")
end)

2 comments

0

OP's script was stolen from Wiki.

0

Thank you.

it is supposed to be

game.Players.PlayerAdded:Connect(function(player)

not

Players.PlayerAdded:Connect(function(player)

1 comment

2

He has a variable for Players

This discussion is preserved as it was. New answers, comments, and votes are closed.