What do you want to achieve? I want to achieve a script that loops thru all the players.
What is the issue? My In pairs function doesn’t get all the players. It only gets 1 player (yes i have tested with other people)
What solutions have you tried so far? Changing it to Ipairs, pairs, Making "Game.Players:GetChildren(), Making Game.Players:GetPlayers()
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
function CheckSight(Players)
-- THE "PLAYERS" Variable IS game.Players:GetPlayers()
for i, v in ipairs(Players) do
local char = v.Character
print(v)
end
end
Heres a preview of the script. It only prints 1 player name.
if the Players Variable is saved at the beginning of the script (the start of the server). It wont update when a player joins/leaves (since its a preassigned table)
function CheckSight(Players)
-- Remove the "Players" Variable
for i, v in ipairs(game.Players:GetPlayers()) do
local char = v.Character
print(v)
end
end
function CheckSight(Players)
-- Remove the "Players" Variable
for _, v in pairs(game.Players:GetPlayers()) do
local char = v.Character
print(v)
end
end
function CheckSight(Players)
-- Remove the "Players" Variable
for _, v in pairs(game.Players:GetPlayers()) do
local char = v:WaitForChild("Character")
print(v)
end
end
That isnt the problem. The problem is that it doesn’t get all players. Print(v) doesn’t have anything with the char todo. It shall print the Instances name witch is the Player.
Yeah, alright. The issue should be you doing player:WaitForChild("Character"), since the Character is a property of the player, not a instance. Change it to player.Character.