I want to make sure the part doesnt go past 3.9 on the zed axis how can I add an if statement checking for this??
I just get an error with this code.
local function inspect_Zoom(check)
if check then
--print("Wheel went backwards!")
if targetsModelVariable:GetPrimaryPartCFrame() >= Vector3.new(0, 0, 3.9) then
print("TooFarForward")
else
targetsModelVariable:SetPrimaryPartCFrame(targetsModelVariable:GetPrimaryPartCFrame() + Vector3.new(0,0,0.3))
end
else
--print("Wheel went forward!")
if targetsModelVariable:GetPrimaryPartCFrame() >= Vector3.new(0, 0, -3.9) then
print("TooFarBack")
else
targetsModelVariable:SetPrimaryPartCFrame(targetsModelVariable:GetPrimaryPartCFrame() - Vector3.new(0,0,0.3))
end
end
end
What are you trying to do? I’m confused by your question.
What is this targetsModelVariable
? How is it moving in the first place?
It is a model that im just moving on the zed axis forward or back depending on the players scroll wheel I want to make sure it doesnt go over (0, 0, 3.9)
or under (0,0,-3.9)
You can’t compare a CFrame with a Vector (or even a Vector with a Vector for that matter!). It’s like saying “is this cat less than this cat”.
Check just the Z component of the CFrame instead.
How could I do this? Sorry for my lack of knowledge I am just learning more about math operations as well as CFrame operations in roblox.
It’s okay!
You know what a Vector3 is?
A CFrame is like a Vector3, but it includes rotation information as well as position.
That doesn’t really matter for you though, because you just care about the position anyways.
CFrames have an X, Y, and Z property just like Vector3s, and they mean the same thing.
So you can do:
if targetsModelVariable:GetPrimaryPartCFrame().Z >= 3.9 then
Notice the .Z part. Now you just have numbers on both sides of the >= and the world makes sense again.
I know most of the before part I didnt know you can axis a specific axis just by using .Z though thanks for this feedback ill try it.
One more thing: your first one should probably be a <, instead of >=.
Yep haha just changed that right now thanks!