Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Delay before a block is moved?

I am trying to change a value after the player touches a part and immediately move the part away from the player to prevent the player from triggering the script multiple times. This does move the part in time, some times but most of the time the player ends up touching the part and triggering the script multiple times anyways. Any suggestions?

Here is my code:

function onTouched(part) 
	local h = part.Parent:findFirstChild("Humanoid") 
	if h~=nil then 
		script.Parent.Position = Vector3.new(-12.15, 621.894, 47.98)
		print("test")
end
script.Parent.Touched:connect(onTouched)

"test" is being printed multiple times when the part is touched.

1 answer

✓ Accepted answer

Instead of a moving part, you could use "debounce".

Once you hit the part, it will take 5 seconds for you to be able to fit it again and gain another point.

local debounce = true
local part = script.Parent

part.Touched:Connect( function()
        if debounce == true then
            --change value --
            debounce = false
            wait(5)
            debounce = true
        end
    end
)

And if you would like to keep it as a moving part, you could just make it teleport.

Using this would change the position of the part without it moving slowly.

local part = script.Parent
part.Touched:Connect(function()
--change value--
part.CFrame = CFrame.new(-2, 2, 4)
end)

4 comments

0

oh

0

brb test it

0

Understood the note, I'll do that next time.

0

tyvm

This discussion is preserved as it was. New answers, comments, and votes are closed.