--------------------------------
--bob up and down part
local amplitude = 0.4
local magnitude = 2
local part = script.Parent
local defaultCFrame = part.CFrame
game:GetService("RunService").Stepped:Connect(function()
part.CFrame = defaultCFrame + Vector3.new(0, amplitude*math.sin(tick()*math.pi/magnitude), 0)
end)
-----------------------------------
--rotation part
while true do
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,0.04,0)
wait(0.01)
end
what im trying to do is make a part bob up and down while rotating but it’s ONLY bobbing up and down, not rotating. i’ve tried putting them into two different scripts but that still didn’t work. any suggestions on how i could fix this
In the example the first function does not effect the rest of the code with the task.wait(). I suck at explaining so here’s a link Roblox Globals – just scroll down to spawn
--------------------------------
--bob up and down part
local amplitude = 0.4
local magnitude = 2
local part = script.Parent
local defaultCFrame = part.CFrame
game:GetService("RunService").Stepped:Connect(function()
part.CFrame = defaultCFrame + Vector3.new(0, amplitude*math.sin(tick()*math.pi/magnitude), 0)
end)
-----------------------------------
--rotation part
task.spawn(function()
while true do
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,0.04,0)
wait(0.01)
end
end)
--------------------------------
--bob up and down part
local amplitude = 0.4
local magnitude = 2
local part = script.Parent
local defaultCFrame = part.CFrame
--rotation part
task.spawn(function()
while true do
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,0.04,0)
wait(0.01)
end
end)
game:GetService("RunService").Stepped:Connect(function()
part.CFrame = defaultCFrame + Vector3.new(0, amplitude*math.sin(tick()*math.pi/magnitude), 0)
end)
My bad, the first script should of worked perfectly fine, its the fact that you are changing the CFrame in both loops, try setting the defaultCframe every loop in the RunService and working off that
this should work:
--------------------------------
--bob up and down part
local amplitude = 0.4
local magnitude = 2
local part = script.Parent
local defaultCFrame = part.CFrame
--rotation part
task.spawn(function()
while true do
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,0.04,0)
wait(0.01)
end
end)
game:GetService("RunService").Stepped:Connect(function()
defaultCFrame = part.CFrame
part.CFrame = defaultCFrame + Vector3.new(0, amplitude*math.sin(tick()*math.pi/magnitude), 0)
end)
this works, although it totally breaks the bobbing in a way. so before we fixed it, it bobbed how i wanted it to. now it bobs up and down ~100 studs and changing the amplitute and magnitude variables don’t do anything
--//Services
local RunService = game:GetService("RunService")
--//Variables
local part = script.Parent
local defaultCFrame = part.CFrame
--//Controls
local amplitude = 0.4
local magnitude = 2
local rotation = CFrame.fromEulerAnglesXYZ(0, 0.04, 0)
--//Functions
coroutine.wrap(function()
while part do
part.CFrame *= rotation
task.wait(0.01)
end
end)()
RunService.Stepped:Connect(function()
part.CFrame = defaultCFrame + Vector3.new(0, amplitude * math.sin(tick() * math.pi/magnitude), 0)
end)
local amplitude = 0.4
local magnitude = 2
local part = script.Parent
local defaultCFrame = part.CFrame
local rotation
task.spawn(function()
local i = 0.04
while true do
rotation = CFrame.fromEulerAnglesXYZ(0,i,0)
wait(0.01)
i += 0.04
end
end)
game:GetService("RunService").Stepped:Connect(function()
part.CFrame = defaultCFrame*rotation + Vector3.new(0, amplitude*math.sin(tick()*math.pi/(magnitude)), 0)
end)