Script stuck playing

this script keeps playing even after the move finishes


I need to know how to stop it unless the move is used again

The script IS stopping, however it isn’t doing anything regarding the touched connection.

Currently, it is creating a new connection every .5 seconds, 5 seconds. At the conclusion of it, you have 10 touched events active, meaning the player will still take damage.

You should only have 1 connection total, and you should disconnect it at the conclusion of the while loop. Additionally, your code can be reduced a bit, as some stuff is a bit redundant:

i.e.

local TimeLeft = 5
local Connection = char:WaitForChild("RightHand").Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid:TakeDamage(3)
	end
end)
while TimeLeft > 0 do
	task.wait(0.5)
	TimeLeft = TimeLeft - 0.5
end
Ruinanim:Stop()
RuinAtionPlaying = false
Connection:Disconnect()

I’m assuming that you wanted the player to take damage every 0.5 seconds, in which case you should have the code be like this:

local TimeLeft = 5
while TimeLeft > 0 do
	task.wait(0.5)
	TimeLeft = TimeLeft - 0.5

	for _, part in char:WaitForChild("RightHand"):GetTouchingParts() do
		if part.Parent:FindFirstChild("Humanoid") then
			part.Parent.Humanoid:TakeDamage(3)
		end
	end	
end
Ruinanim:Stop()
RuinAtionPlaying = false

when I implemented the code it doesn’t do damage.

You’ll need to provide more information regarding how you want the system to work.

Also, does the code I sent error? (Did you try both variations)?

nvm i was able to work them into my own scripts

also the first one was useful while the 2nd didn’t do any damage and gave no errors

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.