Help with cancelling a wait

ValueThing.Changed:Connect(function)
ClearValue(ValueThing.Value)
end)

function ClearValue(Val)
if ValueThing then task.defer(function()
task.wait(4)

	if ValueThing.Value == Val then
		ValueThing.Value = ""
	end
end

end)
end

also use task.wait() for better optimization

2 Likes

Nope, didn’t work either, the wait still proceeds even when the value is changed.

1 Like
local CachedValue = nil
function ClearValue(Val)
	if Val then
		CachedValue = Val
		task.delay(4,function()
			if CachedValue == ValueThing.Value then
				print("value stayed the same")
			else
				print("changed")
			end
		end)
	end
end
ValueThing.Changed:Connect(function)
ClearValue(ValueThing.Value)
end)
2 Likes

Sorry for taking long to respond.

It acts really odd, sometimes the delay time is really short, like if the value is changed, and it resets afterwards, and then change it again, it will take like 1 second to reset.

1 Like