so basicly i made a script that goes thruu spawn points and “should” use the first avaliable, but i cant figure out what line i should use to make it use the first avaliable child instead of looping thruu all the others avaliable.
What is your script now? I may have misread your question and instead you should put a break at the bottom of the v.Available.Value = false line like the first reply suggested.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
game.ReplicatedStorage.Remotes.FirePlayerSpawn.OnServerEvent:Connect(function()
local firstSpawn = spawnpoints:GetChildren()[1]
for i, v in pairs(firstSpawn) do
if v.Avaliable.Value == true then
local HRP = character:WaitForChild(“HumanoidRootPart”)
HRP.CFrame = CFrame.new(v.Point.Position)
v.Avaliable.Value = false
end
end
end)
end)
end)
I have tried using break but nothing changes for me when using break
Rewrote the script to have clearer names of the variables in the for loop, to not create a giant mess of memory leaks and potentially fixed your problem with the break statement
local spawnpoints = game.Workspace.SpawnPoints
game.ReplicatedStorage.Remotes.FirePlayerSpawn.OnServerEvent:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait() --get the character from the player in the remote event
for _, spawn in spawnpoints:GetChildren() do
local Available = spawn.Available
if Available.Value then
Available.Value = not Available.Value --make it not true, which is false
local HRP = character:WaitForChild(“HumanoidRootPart”)
HRP:PivotTo(CFrame.new(spawn.Point.Position))
break --after doing the process on the first spawnpoint, break the loop.
end
end
end)