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 6 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 6 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 — 6y
0
Thank you. kees31ALT 5 — 6y
Ad
Log in to vote
-1
Answered by 6 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 — 6y

Answer this question