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

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

Asked by 5 years ago
Edited 5 years ago

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

0
what do you mean? robloxsario 76 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

0
Did you actually copy KingLoneCat. I will fix the formatting because it is way too big User#24403 69 — 5y
0
Yes he did. DeceptiveCaster 3761 — 5y
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. IdealistDeveloper 234 — 5y
Ad

Answer this question