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

I can't find the Bug, would somebody help me?

Asked by
Xianon 105
10 years ago
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)
0
What's the problem? Just posting code doesn't tell us what we should be looking for. User#2 0 — 10y
0
Well, it seems when i test the script no action is executed, it seems the error is in Player.Name == , but i'm not so sure. Xianon 105 — 10y

2 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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!

Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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.

Answer this question