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

You don't take damage if you stand still? (GetTouchingParts, Touched)

script.Parent.Touched:Connect(function()
	for i, hit in pairs(script.Parent:GetTouchingParts())do
	print(hit.Name)
	if game.Players:GetPlayerFromCharacter(hit.Parent) and script.Parent.Active.Value == true then
	if workspace.RageMode.Value == false then
	hit.Parent.Humanoid:TakeDamage(50)
	script.Parent.Active.Value = false
	else
	hit.Parent.Humanoid:TakeDamage(100)
	script.Parent.Active.Value = false
	end
	end
	end
end)

(This script is related to a beam that surrounds you, and you take damage if you're inside the beam.

For some reason, the player has to be moving for them to take damage, because standing still results in immunity, and I'm not sure why? It's not related to any errors, I'm guessing it's an updated part thing.

4 comments

0

Thats why .Touched is depressing... Sadly I had this problem, to solve it I just put it all in a loop with a coroutine..

0

You could try to find the character's position relative to the beam and if the position of the character is within the beam, take damage with a loop, and if the player gets out of it, then stop dealing damage. This function would be activated first by the touched event.

0

use rays.

0

Oh I think I found a better solution, haven't used the touched event in a few months, so idk if it will work, but I'm going to type it up anyway.

1 answer

✓ Accepted answer

I have a coroutine handle the actual damage part so that when you want to deal damage (when a player is detected in the beam), it starts up the coroutine with what you want to be damaged, the value to damage each loop, and how many seconds until you loop again. When a player leaves, the TouchEnded event fires and "kills" the coroutine.

Now I kept everything mostly the same as your original script because I wasn't sure if you were doing some sort of location damage or something else, but if you are not doing that, then I suggest you only check if the player's HumanoidRootPart is touching the beam because in my current version, if the player's arm ends up sticking out of the beam, the damage will stop.

If this answers your question, then remember to mark it as the accepted answer.

local damage=false

local dealDamage = coroutine.create(function(humanoid,val,waitTime)
	while damage do
		humanoid:TakeDamage(val)
		wait(waitTime)
	end
end)

script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) and script.Parent.Active.Value == true then
		if workspace.RageMode.Value == false then
			damage = true
			coroutine.resume(dealDamage, hit.Parent.Humanoid,50)
			script.Parent.Active.Value = false
		else
			damage = true
			coroutine.resume(dealDamage, hit.Parent.Humanoid,100)
			script.Parent.Active.Value = false
		end
	end
end)

script.Parent.TouchEnded:Connect(function()
	if coroutine.running(dealDamage) then
		damage=false
	end
end)

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