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

How would I delay the damage in this script?

So i'm trying to make a bossfight attack where it shoots raycast lasers, as i'm also trying to make it delay the part where it actually deals damage, so that the player has a chance to actually avoid taking damage if they just keep moving.

Problem is, it doesn't do damage at all, unless you purposefully walk into the laser, mainly if you walk towards the direction it's coming from.

It doesn't even damage you if you stand still.

function LAZER() 
	local function RandomPlayer()
		local players = game.Players:GetPlayers()
		if #players > 0 then
          	return players[math.random(#players)]
    	end
	end
	
	
	for i = 1, 3 do
		local Plr = RandomPlayer()
		
		local Chr = Plr.Character	
		
		if Plr.Character and Chr:FindFirstChild("Torso") and Chr.Humanoid.Health > 0 then
		wait(0.1)
		local Lazor = Instance.new("Part", workspace)
		Lazor.Anchored = true
		Lazor.CanCollide = false
		Lazor.Material = "Neon"
		Lazor.BrickColor = BrickColor.new("Lavender")
		Lazor.TopSurface = 0
		Lazor.BottomSurface = 0 
		
		workspace.Sounds.Lazer:Play()
		
		game:GetService("Debris"):AddItem(Lazor, 2)
		
		local TorsoPos = Chr.Torso.Position
			Lazor.Size = Vector3.new(1, 1, (workspace.Tizona.AttackPart1.Position - TorsoPos).magnitude)
			Lazor.CFrame = CFrame.new(workspace.Tizona.AttackPart1.Position,TorsoPos)
			Lazor.CFrame = Lazor.CFrame + Lazor.CFrame.lookVector*((workspace.Tizona.AttackPart1.Position - TorsoPos).magnitude/2)
			wait(0.9) --Where I tried to make the delay
			Lazor.touched:connect(function(hit)
				local humanoid = hit.Parent:FindFirstChild("Humanoid")
				if humanoid then humanoid:TakeDamage(15)
					if not humanoid then 
					end
				end
			end)
			wait(.01)
		end
	end
end

2 comments

0

I don't see any raycasting in your script.

0

Well, I couldn't think of anything else to call it, honestly.

1 answer

I think Touch events only fire once each time a part touches. It won't fire continuously to continue dealing damage. For example if it fires into an unmoving torso, it only fires once or maybe not at all. Then it just waits. Since the part is not collideable you can instead keep checking the Lazor:GetTouchingParts() list?

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