Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

PlayerAdded event doesn't work?

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago

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)
0
OP's script was stolen from Wiki. User#19524 175 — 5y
0
Thank you. kees31ALT 5 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago

it is supposed to be

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

not

Players.PlayerAdded:Connect(function(player)
2
He has a variable for Players Golubian 37 — 5y

Answer this question