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

How can i make this force-script that uses for-loops shorter?

Asked by 5 years ago

I have used for-loops in order to make a certain force apply while a CFrame-animation is playing. It makes everything lag and i am sure it's possible to make this smaller, but i don't know how...

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

script.Parent.TouchEnded:connect(function(hitPart)
if hitPart:FindFirstChild('BodyForce') then
    hitPart.BodyForce:Destroy()
end
toggle = false
end)
end
0
Is it like possible to include all for-loops in one loop? ZURUgamer 7 — 5y

Answer this question