How To Make Parts Rotate With One Script

I have a folder with balls in it and i am trying to make them all rotate with one script. What I am doing is not working. Can someone help?

This script is a normal script in ServerScriptService

local TweenService = game:GetService("TweenService")
local Folder = game.Workspace.Map.Orbs --Location of Orb

local function bindDummy(EachOrb) --Start fuction
	local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, math.huge, true)
	local tween = TweenService:Create(EachOrb, info, {CFrame = EachOrb.CFrame * CFrame.new(0, 1.5, 0)})
	tween:Play()
end --End function

for _, EachOrb in pairs(Folder:GetChildren()) do -- Bind all existing dummies
	bindDummy(EachOrb)
end --End for
Folder.ChildAdded:Connect(bindDummy) -- Bind all future dummies
17 Likes

What you have coded only runs once so the balls rotate once by 1.5.
you should put this in a while loop to work indefinitely. If you don’t want a while loop to stop the rest of the script put in in a coroutine

local TweenService = game:GetService("TweenService")
local Folder = game.Workspace.Map.Orbs --Location of Orb

local function bindDummy(EachOrb) --Start fuction
    coroutine.wrap(function()
       while task.wait(0.02) do -- change the waiting time according to how fast you want the balls to rotate
	      local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, math.huge, true)
	      local tween = TweenService:Create(EachOrb, info, {CFrame = EachOrb.CFrame * CFrame.new(0, 1.5, 0)})
	      tween:Play()
        end
    end)()
end --End function

for _, EachOrb in pairs(Folder:GetChildren()) do -- Bind all existing dummies
	bindDummy(EachOrb)
end --End for
Folder.ChildAdded:Connect(bindDummy) -- Bind all future dummies
5 Likes

Do you want them to move AND rotate or just rotate? How much do you want them to rotate? Do you want them to reverse or just keep spinning?

4 Likes

I want them to keep spinning over and over and and both if able

4 Likes

Just use vector3 and then () and then in the () put the orientation and then wait a certain time period and rotate it further. and rinse and repeat

4 Likes

That script moves the parts up and down without rotation. And math.huge in the TweenInfo allows the tween to repeat infinitely.

4 Likes

That did not work--------------

4 Likes

When I see your code I think you want them to spin.
If you want to do it in a single script, you have no choice but to use corounites.

local TweenService = game:GetService("TweenService")
local Folder = game.Workspace.Map.Orbs --Location of Orb

local function bindDummy(EachOrb) --Start function
	coroutine.resume(coroutine.create(function()
		while task.wait() do
			EachOrb.CFrame = EachOrb.CFrame * CFrame.Angles(0, 0.05, 0)
		end
	end))
	
	local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, math.huge, true)
	local tween = TweenService:Create(EachOrb, info, {Position = EachOrb.Position + Vector3.new(0, 1.5, 0)})
	tween:Play()
end --End function

for _, EachOrb in pairs(Folder:GetChildren()) do -- Bind all existing dummies
	bindDummy(EachOrb)
end --End for
Folder.ChildAdded:Connect(bindDummy) -- Bind all future dummies
6 Likes

Is it possible to add this in it to

WaitTime = 10 -- How many seconds to respawn the coin!
Amount = 1 -- Amount of coins per coin!
function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if (h~=nil) then
		local thisplr = game.Players:FindFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
			local stats = thisplr:findFirstChild("leaderstats")
			if (stats~=nil) then
				local Score = stats:findFirstChild("Coins")
				if (Score~=nil) then
					Score.Value = Score.Value + Amount
				end
			end
		end
		script.Parent.ParticleEmitter.Enabled = false
		script.Parent.PointLight.Enabled = false	
		script.Parent.Transparency = 1
		script.Disabled = true
		task.wait(WaitTime)
		script.Parent.Transparency = 0
		script.Disabled = false
		script.Parent.ParticleEmitter.Enabled = true
		script.Parent.PointLight.Enabled = true	
	end
end

script.Parent.Touched:Connect(onTouched)
5 Likes

Oh ya it also worked thanks!!!

4 Likes

or you could make it much easier and do this

sphere = script.Parent
a = 0
 repeat
  sphere.Rotation = Vector3.new( 0, a, 0) --The second value of vector3 is a,
  wait(.01) 
  a = a+3 
 until pigs == 1 
4 Likes

The one that Pyracolle made work and I understand it better then this one

3 Likes

lemme explain. a is the beginning starting point and what it is doing is is its adding 3 to the orientation every 0.01 seconds. Vector 3 basically means new point

2 Likes

The issue is the naming of the variables that you used. It’s not easy to figure out what “a” or “pigs” means or why we’re waiting for pigs to == 1

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.