If Statement Question

So, I have been making a small project that is practicing my scripting. I ran into an issue when trying to make an if statement. I want this GUI text button to only do change the material of this part when a different part is at a specific location in the map. SO when the part is at the certain place and you click the text button, it changes the material of the other part, but if the part is at a different location and you click the text button, there is no change with the other part. I don’t know if this makes sense or not, but here are some pictures…

Note: I am not a professional scripter, so I won’t be offended if you point something out to me, this is all learning for me!

image

Is this script even right? What do I need to change? I am open to anything.

1 Like

You want to do

workspace.Heart.Material = Enum.Material.Neon
wait(0.1)
workspace.Heart.Material = Enum.Material.Plastic
1 Like

.Position == Vector3.new(9.4, 21.35, -18.75)

1 Like

To compare a part’s position you have to use the Vector3 object.

if game.Workspace.Orb.Position == Vector3.new(9.4, 21.35, -18.75) then

Also there’s a chance that still may not work due to floating point precision, so you should consider something like:

if game.Workspace.Orb.Position:FuzzyEq(Vector3.new(9.4, 21.35, -18.75), 1e-3) then
2 Likes

Depending on what you are doing you may want to use distance rather than the exact position

Here is an example:
MagnitudeTest.rbxl (25.2 KB)

1 Like