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

How do i make this Force script make the game less laggy?

Asked by 5 years ago

I made a giant script and it just lags everything in the game. I feel like i have to repeat a lot of the same kinds of script. I even made this script for multiple parts, so that might be one of the problems. But how does the game become less laggy with a shorter script?

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
Can you tab your code so people can read it or they will not help. User#5423 17 — 5y
0
tab? How do i do that ZURUgamer 7 — 5y
0
F9 MaxDev_BE 55 — 5y

Answer this question