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

For some reason the output of this code says plr is not a valid member of Players???

Asked by 7 years ago

-- the variable plr should get the players name but for some reason says plr isnt a valid member idk whats wrong :/

a= script.Parent
whatever = game.Workspace
player = script.Parent.Parent.player.Value
wait(1)
while true do
    if whatever.Game.scored.Value == true then
        if a.Value ~= "" then
            plr = a.Value
            if game.Players.plr.TeamColor == game.Players.player.TeamColor then
                game.Players.plr.scored.Value = game.Players.plr.scored.Value + 1
            end
        end
    else
        wait()
    end
end

1 answer

Log in to vote
-2
Answered by 7 years ago

The script thinks that you are locating an object called plr. To fix this all you have to do is put brackets around the variable like this: [plr]

The dot must go after the brackets not before.

Your script should look a little like this:

a= script.Parent
whatever = game.Workspace
player = script.Parent.Parent.player.Value
wait(1)
while true do
    if whatever.Game.scored.Value == true then
        if a.Value ~= "" then
            plr = a.Value
            if game.Players[plr].TeamColor == game.Players[player].TeamColor then
                game.Players[plr].scored.Value = game.Players[plr].scored.Value + 1
            end
        end
    else
        wait()
    end
end
0
I understand that if plr is a number but plr is a string value with the players name. So wouldnt the brackets be unnecessary? windstrike 27 — 7y
0
no, the brackets tell the script that you are locating an object with the name of (string value) GammaShock 32 — 7y
0
It gave me the error: 9: '<name>' expected near '[' windstrike 27 — 7y
0
where is the script located, this will give me an idea of what you are trying to do GammaShock 32 — 7y
View all comments (4 more)
0
its inside a tool that a player has. once player throws the ball a which is a string value would store the player who throws it. windstrike 27 — 7y
0
In other words plr and player varaibles are string values with the name of the players. This is also why i feel like the brackets are unneccary windstrike 27 — 7y
0
The brackets are necessary. Let me explain. When you are trying to locate the player you want to find the players whose name is equal to the plr variable. This won't work unless you put the brackets around it. What the brackets do, is tell the script: alright so i'm here and now i need to find the person who's name is stored in plr variable. As for the error in your script, I believe there might b GammaShock 32 — 7y
0
be stored from another script GammaShock 32 — 7y
Ad

Answer this question