Beam damage ticking

I need a script that does single ticks of damage every 0.1 seconds that damages every part touching it during that tick. I tried this but it didn’t get very far because I realized that I don’t know how to add a part of the script that is needed for it work.

For more of an idea of what I’m talking about, attack someone in Kaiju Universe using a beam.

2 Likes

Could you show your existing code? You can do this by using a while loop and :GetPartsInParts by the way.

4 Likes

I already removed the code. I don’t know if I can repeat it.

1 Like

You can use the :GetPartsInPart() as mentioned by @Katrist to check for what or who is in the beam, and if it finds a humanoid, you reduce it’s health by a set amount.
A possibility is to set the function in a repeat until loop, and create a variable that decides the duration of the beam, and a counter that counts up to the duration until counter >= duration.

1 Like

Can we not see your previous code? You probably saved the place before deleting the script or something try recovering that version.

2 Likes

i didnt save before deleting it

1 Like

Oh Well, You did ask for a script so here’s a script which would damage players If they are inside that part. For it to work Make sure you have CanCollide set to false, And CanTouch set to true. This may not be the best one but It works.

local RATE = 5 --How often to damage
local lastHit = -1 --tick whenever the part damages someone. So we can know when to damage the players inside

local DAMAGE = 10

game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
	if tick() - lastHit < RATE then return end --Check if we still got some time before damaging players inside
	
	for i, child in pairs(script.Parent:GetTouchingParts()) do
		task.spawn(function() -- Lets just spawn a function so the loop can run with out a delay, making everyone almost lose health at the same time
			local Hum = child.Parent:FindFirstChild("Humanoid")

			if Hum ~= nil and Hum.Health > 0 then
				lastHit = tick() --Looks like we damaged someone, Lets same the time so we can know when we last damaged a player
				child.Parent.Humanoid.Health -= DAMAGE
			end
		end)
	end
	
end)
2 Likes

is there a way to make this work better for custom characters with added parts inside the main character?

1 Like

Yes,

When you have multiple parts within a limb you need to do an additional check to find the humanoid. Your goal is to find the Character Model and then find the Humanoid.

local HitCharacter = child.Parent:FindFirstAncestorWhichIsA("Model") --Get character model
local Hum = child.Parent:FindFirstChild("Humanoid") or HitCharacter:FindFirstChild("Humanoid") 


2 Likes

where do i put this in the script?

1 Like

image

Replace the local Hum variable from Demonic’s code with the 2 lines I wrote.

3 Likes