local label = game.Workspace.Cool.SurfaceGui.Frame.TextLabel game.Players.PlayerAdded:connect(function(Player) if Players.Player.Name == 'Xianon' then label.Text = ("Welcome Xianon") msg.Text = ("Xianon has entered the game") wait (3) msg:remove() elseif not Players.Player.Name == 'Xianon' then game.Players.Player.Backpack.BT:Destroy() end if Players.Player.Name == 'ApolloTalentz' then label.Text = ("Welcome Apollo") msg.Text = ("Apollo has entered the game") wait(3) msg:remove() elseif not Players.Player.Name == 'ApolloTalentz' then game.Players.Player.Backpack.BT:Destroy() end end)
Two problems with this code.
First, msg is nil. You never created a message.
Second, you keep puttingPlayers.Player.Name
.
Although you can do Workspace like that, with all other services you must do either game.SERVICENAME
or game:GetService("SERVICENAME")
.
But here, you don't need to do even that. Since the PlayerAdded
event has the built in parameter player, you can just put Player.Name
.
Hope I helped!
First, we should look at this expression from line 06:
Players.Player.Name
First, note that Players
is not defined for you. Either you must state Players = game.Players
or just use the name game.Players
explicitly like you do elsewhere in this script.
The period operation is just "syntactic sugar" for table indexing with a string, that is, the above expression is equivalent to this one:
Players["Player"].Name
Note that the purpose of the text Player
here, then is not a variable. It is a string, which means the variable Player
will be ignored.
If Player
were a string value, we would use the explicit table-access syntax with [
and ]
:
Players[Player].Name
Though, if this were the case, that would also be redundant, since clearly Player
is the object's name.
However, Player
is NOT a string. It is a player object, that is, it is that object you are attempting to reference with the incorrect Players.Player
. That means you just use Player.Name
:
if Player.Name == 'Xianon' then -- Revised line 06
The second issue is that you refer to msg
several times, but never define it. You need to create that msg
object before you start doing things to it.