✓ Accepted answer
Here's a cleaned up version of what you wrote (better names, spacing, style) (using :children'' is absurd) that does exactly what you did:
wait(3)
local spawns = game.Workspace.Spawns:GetChildren()
for _, dummy in pairs (game.Workspace.Dummys:GetChildren()) do
wait(0.3)
local RandomSpawn = spawns[math.random(1, #spawns)]
if RandomSpawn:FindFirstChild("Used") then
if not RandomSpawn.Used.Value then
RandomSpawn.Used.Value = true
dummy.Torso.CFrame = CFrame.new(RandomSpawn.Position)
+ Vector3.new(0, 1, 0)
end
end
wait()
end
Remark What happens when the spawn you picked randomly has already been picked? You don't move the dummy; the dummy remains where it is, and you move onto the next one.
You instead ought to continue trying until you manage to place it. A repeat until loop is a brief way to accomplish that.
wait(3)
local spawns = game.Workspace.Spawns:GetChildren()
for _, dummy in pairs (game.Workspace.Dummys:GetChildren()) do
wait(0.3)
local RandomSpawn
repeat
RandomSpawn = spawns[math.random(1, #spawns)]
wait()
until RandomSpawn:FindFirstChild("Used") and not RandomSpawn.UsedValue
RandomSpawn.Used.Value = true
dummy.Torso.CFrame = CFrame.new(RandomSpawn.Position)
+ Vector3.new(0, 1, 0)
end
Alternatively, instead of using Used, you could just remove random objects from your list of spawns, which is much more straightforward:
wait(3)
local spawns = game.Workspace.Spawns:GetChildren()
for _, dummy in pairs (game.Workspace.Dummys:GetChildren()) do
wait(0.3)
local RandomSpawn = table.remove(spawns, math.random(1,# spawns))
dummy.Torso.CFrame = CFrame.new(RandomSpawn.Position)
+ Vector3.new(0, 1, 0)
end
1 comment
Thank you so much!!