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)
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)
it is supposed to be
game.Players.PlayerAdded:Connect(function(player)
not
Players.PlayerAdded:Connect(function(player)