Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make this anim-script make the game less laggy?

Asked by 5 years ago

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
0
are you trying to spin a object? or something else? hellmatic 1523 — 5y
0
This won't fix your problem but change connect to Connect and indent the code properly. lunatic5 409 — 5y
0
im trying to move an object up, then forward and then back/down ZURUgamer 7 — 5y

Answer this question