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

How do i prevent my script from lagging the server?

Asked by 3 years ago
Edited 3 years ago

My current script DOES work, just has a setback, it lags the server pretty hard. any suggestions on optimizing it, so it doesn't lag the server?

local char = script.Parent
local humanoid = char.Humanoid
local head = char.Head

wait(1)
script.Parent.laser.Transparency = 0.5
script.Parent.laser2.Transparency = 0.5
script.Parent.laser3.Transparency = 0.5
script.Parent.laser4.Transparency = 0.5
script.Parent.laser5.Transparency = 0.5
script.Parent.laser6.Transparency = 0.5
script.Parent.Humanoid.WalkSpeed = 0
wait(2)
script.Parent.laser.Transparency = 0
script.Parent.laser2.Transparency = 0
script.Parent.laser3.Transparency = 0
script.Parent.laser4.Transparency = 0
script.Parent.laser5.Transparency = 0
script.Parent.laser6.Transparency = 0
    local db = false
        script.Parent.laser.Touched:Connect(function(hit)
            if db == false then
                db = true
                hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25
            end
        script.Parent.laser2.Touched:Connect(function(hit)
            if db == false then
                db = true
                hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25
            end
        script.Parent.laser2.Touched:Connect(function(hit)
            if db == false then
                db = true
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25
        end
        script.Parent.laser3.Touched:Connect(function(hit)
            if db == false then
                db = true
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25
        end
        script.Parent.laser4.Touched:Connect(function(hit)
            if db == false then
                db = true
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25
        end
        script.Parent.laser5.Touched:Connect(function(hit)
            if db == false then
                db = true
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25
        end
        script.Parent.laser6.Touched:Connect(function(hit)
                if db == false then
                db = true
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25
        end
    end)
end)            
end)            
end)        
end)
end)
end)
wait(1)
script.Parent.laser.Transparency = 1
script.Parent.laser2.Transparency = 1
script.Parent.laser3.Transparency = 1
script.Parent.laser4.Transparency = 1
script.Parent.laser5.Transparency = 1
script.Parent.laser6.Transparency = 1
script.Parent.Humanoid.WalkSpeed = 7

    end

end
0
maybe close ur touched event functions before you start a new one OMGgaming89 2 — 3y
0
you should consider using more conventional scripting though OMGgaming89 2 — 3y
0
You provided very little information. I don't know what your hierarchy looks like. If you could provide me an image of your hierarchy, I can definitely help. MarkedTomato 810 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Try this

local char = script.Parent
local humanoid = char.Humanoid
local head = char.Head
local db = false

wait(1)
for i = 1,6,1 do
    if i = 1 then
        script.Parent.laser.Transparency = 0.5
    else
        script.Parent.laser..tostring(i).Transparency = 0.5
end
script.Parent.Humanoid.WalkSpeed = 0
wait(2)
for i = 1,6,1 do
    if i = 1 then
        script.Parent.laser.Transparency = 0
        script.Parent.laser.Touched:Connect(function(hit)
            if db == false then
                db = true
                hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25
            end
        end)
    else
        script.Parent.laser..tostring(i).Transparency = 0
        script.Parent.laser..tostring(i):Connect(function(hit)
            if db == false then
                db = true
                hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25
            end
        end)    
end
wait(1)
for i = 1,6,1 do
    if i = 1 then
        script.Parent.laser.Transparency = 1
    else
        script.Parent.laser..tostring(i).Transparency = 1  
end
Ad

Answer this question