Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i prevent my script from lagging the server?

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

3 comments

0

maybe close ur touched event functions before you start a new one

0

you should consider using more conventional scripting though

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.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.