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

Why do I get this error when getting a random player?

Asked by
OniiCh_n 410 Moderation Voter
10 years ago

I'm trying to give 1 character a specific package (which I have stored in game.ReplicatedStorage.morph), but every time I run the script, I get the following error:

22:08:37.013 - 1 is not a valid member of Players

This error can be found on lines 2-3. A little help as to what may be causing this error?

activePlayers = plrs:GetChildren()
        randomPlayer = plrs[math.random(1, #activePlayers)]
        chosenPlayer = plrs[randomPlayer]
        print(chosenPlayer.Name)
        if chosenPlayer.Character.Humanoid ~= nil then
            m1 = Instance.new("Hint", game.Workspace)
            m1.Text = "Possessing the new Deathspeaker..."
            h = chosenPlayer.Character.Humanoid
            h.Name = "Enemy"
            newMorphs = morph:GetChildren()
            for i = 1, #newMorph do
                cloneMorph = newMorphs[i]:Clone()
                cloneMorph.Parent = chosenPlayer.Character
                wait()
            end

Answer this question