Touch event only works once

Touched event works once, but then it doesn’t work after that.

Script:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if script.Parent.Value.Value == 0 then
			if game.Players:FindFirstChild(hit.Parent.Name).gangSystem.isInGang.Value == true then
				script.Parent.Value.Value = 120
				script.Parent.carryOn.Value = false
				while true do
					wait(1)
					if script.Parent.carryOn.Value == false then
						script.Parent.Value.Value -= 1
						if script.Parent.carryOn.Value == true then
							break
						end
					end
				end
			end
		end
	end
end)

script.Parent.TouchEnded:Connect(function(hit)
	script.Parent.carryOn.Value = true
end)

Help would be highly appreciated.

What should I replace it with then?

In order to stop the loop only.

You only let the script go through if script.Parent.Value.Value == 0 but then you set it to 120 and don’t actually let it go back to 0.
You should break the loop once it reaches 0, not when the player stops touching the part. And if you need the loop to stop once the player stops touching it, then set the value to 0 in the TouchEnded function.

2 Likes