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
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