Spin all spinners

hey,

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

Maybe switch to a Motor 6D instead of using code.

2 Likes

If you really want to use code, from past experience I would use collectionservice.

but I would do what oof said

1 Like

thanks, but i don’t even know how to use Motor6D’s, it is very complicated to me.

is there any other way? i also want to have customizable speed

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.

Nope still only one works

chagsdiuasjdfklasdf

Here is a spinner using a HingeConstraint:

Spinner.rbxl (56.5 KB)

You can adjust the speed by changing the AngularVelocity in the Properties window (or through code).

Screen Shot 2024-11-13 at 6.33.14 PM

Another option might be to clone a script into each spinner.

If they had to clone the script, then it’d be better to just make use of CollectionService.

It seems like a like of wasted computing power to run a while loop for a bunch of spinners.

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.

1 Like

actually fixed it myself by spawning in a function and using the while loop in there

1 Like

I don’t think loops make the game lag that much. (I may be wrong)