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 4 years ago

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

01script.Parent.MouseButton1Click:Connect(function()
02    local Slot = script.Parent.Parent.Parent.Parent:GetChildren()[math.random(1,#script.Parent.Parent.Parent.Parent:GetChildren())]
03    if Slot.Name == "Slot1" then
04        if Slot.Visible == false then
05            script.Parent.Parent.Visible = false
06            local players = game.Players:GetChildren()
07            for i = 1,#players do
08                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Visible = true
09                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Difficulty.Text = script.Parent.Parent.Vals.Difficulty.Value
10                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Host.Text = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Name
11                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Mission.Text = script.Parent.Parent.Vals.Mission.Value
12                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Players.Text = "Players: 1/4"
13                game.Players[i].PlayerGui.MainGui.Missions[Slot.Name].Host.HostName.Value = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Name
14                game.StarterGui.MainGui.Missions[Slot.Name].Visible = true
15                game.StarterGui.MainGui.Missions[Slot.Name].Difficulty.Text = script.Parent.Parent.Vals.Difficulty.Value
View all 31 lines...

Anything wrong with it?

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

1 answer

Log in to vote
1
Answered by
Elyzzia 1294 Moderation Voter
4 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 — 4y
Ad

Answer this question