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