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

How do I make my decrease Y CFrame script not rotate?

Here is the script:

script.Parent.PrimaryPart = script.Parent.Bottom
local debounce = false
local root = nil
root = script.Parent.PrimaryPart

while wait() do
	local rootPos = root.Position
		if rootPos.Y > -11.471 and debounce == false then
     		debounce = true
				print("no fly")
				local dir = root.CFrame.LookVector
				root.Anchored = true
				root.CFrame = CFrame.new(rootPos.X, -11.471, rootPos.Z) * CFrame.Angles(0, -math.asin(dir.X), 0)
				root.Anchored = false
        wait()
        debounce = false
    end
end

Problem is it rotates because the rotation is changing with the CFrame, how would I fix this? If anyone has improvements on anything else I would like to know that as well.

1 answer

hey so i'm just gonna solve this by commenting on/editing your code because i'm big lazy

local debounce = false
local root = script.Parent.Bottom
script.Parent.PrimaryPart = root

while wait() do
    local rootPos = root.Position
        if rootPos.Y > -11.471 and not debounce then -- 'debounce == false' can be replaced by 'not debounce' but it doesn't really matter. why is there a debounce here if it'll always be firing whenever the debounce is false?
            debounce = true
                print("no fly")
                local dir = root.CFrame.LookVector
                root.Anchored = true --there's no need to anchor this here
                root.CFrame = CFrame.new(rootPos.X, -11.471, rootPos.Z) * CFrame.Angles(0, -math.asin(dir.X), 0) -- you're multiplying by a new CFrame.Angles() every time you change its position, so it's going to rotate every time this iterates.
                root.Anchored = false --you're anchoring it then unanchoring after the insanely small fraction of a second that roblox takes to read these lines.
        wait() --why do you have two wait()'s in the loop?
        debounce = false
    end
end

i think a lot of the stuff here is just like, you trying to troubleshoot without knowing exactly what's happening so i get it. so essentially, you have two options i think, even though i'm not entirely sure what you're trying to do.


local root = script.Parent.Bottom
script.Parent.PrimaryPart = root
 local dir = root.CFrame.LookVector

while wait() do
	local rootPos = root.Position
	if rootPos.Y > -11.471 then
	print("no fly")
	root.CFrame = CFrame.new(rootPos.X, -11.471, rootPos.Z) * CFrame.Angles(0, -math.asin(dir.X), 0)
	end
end

so this one should root it to one CFrame, then base the CFrame.Angles() that you multiply it by off of one LookVector that won't be changed. if you're just trying to set it to that specific Y coordinate and not change its rotation at all, then you could do . . .


local root = script.Parent.Bottom
script.Parent.PrimaryPart = root

while wait() do
	local rootPos = root.Position
	if rootPos.Y > -11.471 then
		print("no fly")
		root.CFrame = root.CFrame + Vector3.new(0,-(root.Position.Y+11.471),0)
	end
end

which will essentially just take its current position on the Y-axis, add the offset that you want to it, and subtract it from its current position

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