Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

-- 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

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

8 comments

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?

0

no, the brackets tell the script that you are locating an object with the name of (string value)

0

It gave me the error: 9: '' expected near '['

0

where is the script located, this will give me an idea of what you are trying to do

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.

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

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

0

be stored from another script

This discussion is preserved as it was. New answers, comments, and votes are closed.