i want to make an obby game with spinners so I have this script.
this script only works with one spinner however because of the while loop.
how do I get past this and make it work with all the spinners while still having one local script (so its client sided) that can handle all of them? thanks
for _, v in ipairs(workspace:WaitForChild("Spinners"):GetChildren()) do
if v.Name == "Spinner" and v:IsA("Model") then
print("Found a spinner!")
while task.wait() do
v.Part.Orientation += Vector3.new(0, v.Settings:GetAttribute("Speed"), 0)
end
end
end
You could wrap the while task.wait() do in a coroutine.
It might work:
local SpinCoroutine = coroutine.wrap(function()
while task.wait() do
v.Part.Orientation += Vector3.new(0, v.Settings:GetAttribute("Speed"), 0)
end
end)
for _, v in ipairs(workspace:WaitForChild("Spinners"):GetChildren()) do
if v.Name == "Spinner" and v:IsA("Model") then
print("Found a spinner!")
SpinCoroutine()
end
end
But this could be a lot of wasted code execution. Motor 6D would be better.
With collection service you can give all your spinners a tag and your local script can make all spinners with the tag work with just one local script. This is the best way to do this.