What to i change so it wait 5sec before it do it again?

I have this script… What do i change so it wait 5 sec before it do it again?

local part = script.Parent

local function OnTouched(OtherPart)
	local humanoid = OtherPart.Parent:FindFirstChild("Humanoid")
	if humanoid then
		OtherPart.Parent:ScaleTo(0.5)
		wait(5)
	end
end

part.Touched:Connect(OnTouched)

try putting the wait(5) after the if statement

now it waits before it makes me small… i want it to wait after ive been small :slight_smile:

i need the wait bc i get stuck in the bottle haha

are you trying to create a loop or a cooldown perhaps?

no… but i need it for more than one player so i cant destroy it after. i just need it to happen one time per player

So like a cooldown? You can make a debounce variable and make it do the function if debounce is false, and not if true.

local part = script.Parent

local debounce = false

local function OnTouched(OtherPart)
	if debounce then
		return
	end

	debounce = true

	local humanoid = OtherPart.Parent:FindFirstChild("Humanoid")
	if humanoid then
		OtherPart.Parent:ScaleTo(0.5)
		wait(5)
	end

	debounce = false
end

part.Touched:Connect(OnTouched)

i suppose you could create a table, everytime a player touches the part their username is added into the table. every player’s username on the table won’t get affected by the part if touched again.

thank you so much <3 this works great! i dont get stuck in the bottle anymore

1 Like

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