Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Moving part bugs out and moves upwards infinitely when triggered?

Asked by 6 years ago
Edited 6 years ago

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)
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' hellmatic 1523 — 6y

1 answer

Log in to vote
0
Answered by
ax_gold 360 Moderation Voter
6 years ago
Edited 6 years ago

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

Ad

Answer this question