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

How do i compare a CFrame.Position to a Value?

I am not sure how to compare CFrame.Position to a Value. I have tried this and it does not work. Any help in leading me in the right direction would be great. Thanks.

local rock = script.Parent.Parent.Stand4
if rock.CFrame.Position == Vector3(375.839966, -64.2299347, 694.550415) then

end

1 comment

1

if CF.Position == Vector3.new(...) then

1 answer

✓ Accepted answer

To create a vector3, you need to do vector3.new() Theres two ways you can compare vector3's:

v3 = Vector3.new(375.839966, -64.2299347, 694.550415)
local rock = script.Parent.Parent.Stand4
rockPos = rock.CFrame.Position

--you can compare the vector3 values like this:
if(rockPos == v3)then
	print("yes")
else
	print("no")
end

--or you could compare the individual values:
if(rockPos.X == v3.X and rockPos.Y == v3.Y and rockPos.Z == v3.Z)then
	print("yes")
else
	print("no")
end

don't rlly need to do option 2 but its a way of doing things

5 comments

0

Thank you for all the details.

1

You should never do this. Ever. Floating point comparisons with == are the recipe for really hard to diagnose, hard to repro bugs.

1

You should always compare with something like (CFrame.Position - otherPos).Magnitude < 0.001, where the exact tolerance value (here 0.001) depends on how you're moving the parts and how close counts as equal for your application.

1

If you don't think this is true, execute this from Studio's command line: a=0.1 b=0.7 print(a7,b,a7==b)

0

thank you I didn't know that

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