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
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
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
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)
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