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

Why my output says "Player is not a valid member of Players"?

I making a round based game.I make a script on enable and disabling values on the script but It says the output that Player is not a valid member of Players.This is my part of my script that it enable and disabling values.

		local plrs = game.Players:GetChildren()
		for i,v in pairs(game.Players:GetPlayers()) do
		local num = math.random(1,10)
		plrs[i].Character.Head.CFrame = CFrame.new(workspace.Minigame1.Spawns["Spawn"..num].Position)
		plrs[i].Character.Humanoid.WalkSpeed = 0
		game.Players.Player.stats.Playing.Value = true
		game.Players.Player.stats.Winners.Value = false
        end
	break
	end

But why it says on my output that Player is not valid member of players on the lines game.Players.Player.stats.Playing.Value = true game.Players.Player.stats.Winners.Value = false

1 comment

0

what do you mean?

1 answer

✓ Accepted answer

Hi robloxsario,

The reason that your script is erroring is because of your 6th and 7th lines of code. Here, you reference a Player object inside of Players by doing:

game.Players.Player

This causes an error because there is not necessarily going to be a ‘Player’ object inside of Players. So, it tells you that there is no Player inside of the Players service. Instead, I recommend you set a variable for the player and then change the rest later, like so:

local plrs = game.Players:GetChildren()
for i,v in pairs(game.Players:GetPlayers()) do
    local num = math.random(1,10)
    local player = plrs[i] — The new variable for the current player it is looping through.
    local char = player.Character — The character of the current player to stop repetition and make things more organized.
    local stats = player:WaitForChild(‘stats’) — A variable for the stats item inside of the player, to help with stopping repetition and making stuff more organized.
    character.Head.CFrame = CFrame.new(workspace.Minigame1.Spawns["Spawn"..num].Position)
    character.Humanoid.WalkSpeed = 0
    stats:WaitForChild(‘Playing’).Value = true
    stats:WaitForChild(‘Winners’).Value = false
end
break
end

Well, I hope that i helped to some extent and that you are able to fix your script after this fixing this minor mistake.

Thanks, Best regards, Idealist Developer

3 comments

0

Did you actually copy KingLoneCat. I will fix the formatting because it is way too big

0

Yes he did.

0

Don't mess with the formatting of my own answers please. That's not very nice of you. Don't bother with my answers, just worry about helping others.

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