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

1 is not a valid member of Players? It's meant to return a Player?

Asked by 3 years ago

It needs to find all the players so it can change the Properties of a PlayerGui. Here's my script:

script.Parent.MouseButton1Click:Connect(function()
    local Slot = script.Parent.Parent.Parent.Parent:GetChildren()[math.random(1,#script.Parent.Parent.Parent.Parent:GetChildren())]
    if Slot.Name == "Slot1" then
        if Slot.Visible == false then
            script.Parent.Parent.Visible = false
            local players = game.Players:GetChildren()
            for i = 1,#players do
                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Visible = true
                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Difficulty.Text = script.Parent.Parent.Vals.Difficulty.Value
                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Host.Text = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Name
                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Mission.Text = script.Parent.Parent.Vals.Mission.Value
                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Players.Text = "Players: 1/4"
                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Host.HostName.Value = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Name
                game.StarterGui.MainGui.Missions[Slot.Name].Visible = true
                game.StarterGui.MainGui.Missions[Slot.Name].Difficulty.Text = script.Parent.Parent.Vals.Difficulty.Value
                game.StarterGui.MainGui.Missions[Slot.Name].Host.Text = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Name
                game.StarterGui.MainGui.Missions[Slot.Name].Mission.Text = script.Parent.Parent.Vals.Mission.Value
                game.StarterGui.MainGui.Missions[Slot.Name].Players.Text = "Players: 1/4"
                game.StarterGui.MainGui.Missions[Slot.Name].Host.HostName.Value = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Name
            end
        else
            script.Parent.Text = "Error Occured! Try again!"
            wait(2)
            script.Parent.Text = "Ready!"
        end
    else
        script.Parent.Text = "Error Occured! Try again!"
        wait(2)
        script.Parent.Text = "Ready!"
    end
end)

Anything wrong with it?

0
game.Players:GetChildren()[i] not game.Players[i], had that mistake a lot. Remember this. greatneil80 2647 — 3y

1 answer

Log in to vote
1
Answered by
Elyzzia 1294 Moderation Voter
3 years ago

when you do game.Players[i], it's interpreted as you literally trying to get a property or child that's named 1 (not a string, but a number)

what you should be doing instead is game.Players:GetPlayers()[i] or in your case, since you already got the players, players[i]

0
Thanks mate! JB_SuperGamer 165 — 3y
Ad

Answer this question