table.find is returning nil even though the table has the exact string it’s looking for.
for _,v in pairs(game:GetService("Players"):GetChildren()) do
local x = table.find(PlayersPlaying:GetChildren(), v.Name)
print(PlayersPlaying:GetChildren(), v.Name, x)
if x then
print("time")
repeat task.wait() until v.Character
v.Character:MoveTo(workspace.TemporarySpawn.Position)
end
end
You could create a dictionary where each key is the name of the corresponding instance. Normally, there would be the danger of conflicting names, but since this is for players, their names will never be the same.
local function map(instances: { Instance }): { [string]: Instance }
local mapped = {}
for _, instance in ipairs(instances) do
mapped[instance.Name] = instance
end
return mapped
end
local playersPlaying = map(PlayersPlaying:GetChildren())
playersPlaying["PhoenixRessusection"]
playesrPlaying[v.Name]