Trying to detect if player is not already in a certain CFrame

So I need to check if a player is not already rotated and if they are don’t do anything, but it’s passing through the check even when the player is rotated.

if humrp.CFrame ~= (humrp.CFrame * CFrame.Angles(0,0,math.rad(-90))) and Climbing then
	print("Turning")
	humrp.CFrame = (humrp.CFrame * CFrame.Angles(0,0,math.rad(-90)))
end

I’m not the best with CFrames but you can try this

if OriginalCFrame ~= LastCFrame  and Climbing then
	print("Turning")
	humrp.CFrame = (humrp.CFrame * CFrame.Angles(0,0,math.rad(-90)))
end

Replace the OriginalCFrame with the players CFrame before the check and replace the Last CFrame with the players current CFrame

That doesnt seem to be working I tried it just now, the player still rotates after it’s already been rotated

local OriginalCFrame = humrp.CFrame
	if OriginalCFrame ~= (humrp.CFrame * CFrame.Angles(0,0,math.rad(-90))) then
		print("Rotating")
		local Tween = TweenService:Create(humrp, TweenInfo.new(.2, Enum.EasingStyle.Cubic), {CFrame = (humrp.CFrame * CFrame.Angles(0,0,math.rad(-90)))})
		Tween:Play()
	end

Sorry but I think I misunderstood the question, I thought there was a problem with checking the players rotation

type this

local bon = {}

if bon[humrp] ~= "Rotated" then
bon[humrp] = "Rotated"
local Tween = TweenService:Create(humrp, TweenInfo.new(.2, Enum.EasingStyle.Cubic), {CFrame = (humrp.CFrame * CFrame.Angles(0,0,math.rad(-90)))})
Tween:Play()
end

Alright Ill try that mooney thanks!

1 Like

if you want it to be able to be rotated again after a certain amount of time, do this:

local bon = {}

----------------------------------------
--rotation event
if bon[humrp] ~= "Rotated" and Climbing then
bon[humrp] = "Rotated"
local Tween = TweenService:Create(humrp, TweenInfo.new(.2, Enum.EasingStyle.Cubic), {CFrame = (humrp.CFrame * CFrame.Angles(0,0,math.rad(-90)))})
Tween:Play()
delay(5, function()
bon[humrp] = nil
end)
end

What does the delay function do and is this guaranteed to work? And if so what makes it work over the other checks?

Why are you doing “bon[humrp]” what does that mean exactly?

delay spawns a new thread, so it will not interrupt the rest of the script. bon[humrp] is basically just a debounce for that particular humrp object

1 Like

Could spawn(fucntion() be in replace of delay?

And why didn’t my other checks and the ones suggested work?

yes, but it is more efficient to write

delay(5, function()
--stuff
end)

instead of

spawn(function()
wait(5)
--stuff
end)
1 Like

Oh, alright I get it, but why werent my other checks working?

because if your character moves even one microscopic millimeter after being rotated, the cframe will not be equal to

humrp.CFrame * CFrame.Angles(0,0,math.rad(-90))

which makes the script think it hasnt been rotated at all

1 Like

Oh alright, then what makes your script work?

because its not checking if it is allowed to be rotated by its current cframe, but through its existence in a table.

1 Like

oooooooooooooooooooooooooooooooh gotcha, thats really helpful I still need to try your script hold on! ^^ also thanks for all the help and patience just didnt get why my check wasnt working

1 Like

Wouldn’t a BodyGyro be perfect for this job? Just place it in the character’s HumanoidRootPart then set the BodyGyro.CFrame property whenever you want the character to have a certain rotation.

Yea, I was actually thinking about that but like I’d just rather rotate the humrp’s CFrame, if it doesn’t work out then maybe I’ll try that