I got this messy script with C-Frames and particular forces for every new C-Frame animation. But the script makes my game lag big time. How do I resolve this? Btw, i tried Tweenservice, but then the parts suddenly collided.
local toggle = false
local ForceStop = -100
local StartForce = -50000
for i = 1,800 do
wait(0.01)
script.Parent.Touched:connect(function(hitPart)
if toggle == false then
toggle = true
if hitPart.Parent.Parent == game.Workspace then
local force = Instance.new("BodyForce")
force.Parent = hitPart
for i = 1,50 do
force.Force = Vector3.new(0,math.random(-5000,5000),StartForce)-Vector3.new(0,0,i*ForceStop)
wait(0.1)
end
end
end
end)
script.Parent.TouchEnded:connect(function(hitPart)
if hitPart:FindFirstChild('BodyForce') then
hitPart.BodyForce:Destroy()
end
toggle = false
end)
end
wait(5)
local RetreatForce = 50000
for i = 1,500 do
wait(0.01)
script.Parent.Touched:connect(function(hitPart)
if toggle == false then
toggle = true
if hitPart.Parent.Parent == game.Workspace then
local force = Instance.new("BodyForce")
force.Parent = hitPart
for i = 1,50 do
force.Force = Vector3.new(0,math.random(-5000,5000),RetreatForce)-Vector3.new(0,0,-i*ForceStop)
wait(0.1)
end
end
end
end)
script.Parent.TouchEnded:connect(function(hitPart)
if hitPart:FindFirstChild('BodyForce') then
hitPart.BodyForce:Destroy()
end
toggle = false
end)
end

3 comments
are you trying to spin a object? or something else?
This won't fix your problem but change connect to Connect and indent the code properly.
im trying to move an object up, then forward and then back/down