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

Moving part bugs out and moves upwards infinitely when triggered?

I have a script that when a character runs over the top of a part, the part will go sideways a tiny bit, but when it is touched, instead of moving sideways, it will go upwards infinitely. Script:

local Part = workspace.ManholeCover.Union -- this is the Part we will move
local newPos = Part.Position + Vector3.new(-27.313,285.446,-9.8) -- the position the Part will go to
local Time = 0.5 -- the time that the script will take to move the part
local Increment = 0.5 -- the Part will move 0.5 studs each time it moves
local Debounce = false
 
local Diff = newPos - Part.Position -- the difference between the two positions
local Mag = Diff.magnitude -- the distance between the two parts
local Direction = CFrame.new(Part.Position, newPos).lookVector
 
function MovePart() -- function to move the Part
	if Debounce then return end -- end the function if debounce is true
	Debounce = true -- make Debounce true so the function can't run
	for n = 0, Mag, Increment do
		Part.CFrame = Part.CFrame + (Direction * Increment)
		wait( (Time/Mag) * Increment )
	end
	Debounce = false -- set Debounce to false so the function can run again
end
 
workspace.ManholeCover.Union.Cell.Touched:connect(MovePart)

1 comment

0

The debounce sets to true, then sets it to false causing it to run infinitely. Try putting a 'if Part.CFrame == CFrame.new(1, 1, 1) then ... debounce = false'

1 answer

✓ Accepted answer

It's because of the method you use to move the manhole. Using TweenService is a lot easier. I just explained this with an example on another question, and if I put it here I'll pretty much just be repeating myself, so check out what I said in my answer there, please: Link

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