Value goes down extremely fast

Hello, does anyone know why the value is going down at like 10 per second instead of just 1?

Script:

local carryon2

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
			end
		end
	end
end)

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
				carryon2 = false
				while true do
					wait(1)
					if carryon2 == false then
						script.Parent.Value.Value -= 1
						if carryon2 == true then
							break
						end
					end
				end
			end
		end
	end
end)

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

This simply isn’t the case, nor does it fix anything.

local carryon2

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
end
end
end
end)

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
carryon2 = false
while true do
wait(1)
if carryon2 == false then
script.Parent.Value.Value -= 1
if carryon2 == true then
break
end
end
end
end
end
end
end)

script.Parent.Touched:Connect(function(hit)
carryon2 = true
end)

add a print after the wait(1) and see how many times it prints to check

use script.parent.touched, not script.parent.touchedended

script.parent.touchedended basically when the player leaves the part, meaning multiple of the other players body parts can enter it, and deduct the value

Exactly, that’s what I’m trying to do. When the player leaves the part, I want it to stop counting. This is not the issue, the issue is, when touched, it goes down too fast…

wait so when they touch it, it slowly deducts, and when they leave it stops

Yes, exactly what I’m trying to do.

luckily im a professional, and the best scripter ever so ill re-type it, your so greatful to have me

Yeah, I highly doubt that but we’ll give it a shot! :grinning:

Joking, please don’t take that seriously.

if i were you i would just experiment with the deduction number, until u get what u want

Yeah, this just isn’t the fix is it…

why not just use i,v and detect the magnitude of the player to the part-

That’s 100x more complicated and more time deducting. I am sticking to this method, there’s literally 1 issue and that’s the wait(1) not working.

for i,v in pairs(game.workspace.players(getchildren())do
if v.HumanoidRootPart.Position.Magnitude.ToPart then
deduct value

I have managed to get it working now.

May I ask what you did to fix it? My best guess is that the while loop was running multiple times.

I replaced the touch event with:

while true do
	wait(1)
	if carryon2 == false then
		script.Parent.Value.Value -= 1
		if carryon2 == true then
			print("err")
		end
	end
end