# How would I determine if a model was at a certain position?

Hey, I was trying to determine where a model is so I can make it so when it is at that position, it changes an IntValue (currency.) I’ve tried but for some reason, it didn’t work…

The car moves to the left, and when it goes into the tunnel, it gets teleported back to a tunnel behind it.

``````	local car = game.Workspace.deliverycar1
if car.PrimaryPart.CFrame.Position == Vector3.new(164.244, 3.919, -35.681) or Vector3.new(163.244, 3.919, -35.681) or Vector3.new(165.244, 3.919, -35.681) then
eggs.Value = eggs.Value - 100 and cash.Value == cash.Value + 100
end
end)
``````
2 Likes
``````local car = game.Workspace.deliverycar1
local positions = {
Vector3.new(164.244, 3.919, -35.681),
Vector3.new(163.244, 3.919, -35.681),
Vector3.new(165.244, 3.919, -35.681)
}

if table.find(positions, car.PrimaryPart.CFrame.Position) then
eggs.Value += 100
end
``````

also pick one, are you subtracting 100 or adding 100

I’m adding cash and subing eggs, also I don’t need all of the positions, I was just doing that to see if it wasn’t working because the car was moving too many studs or half studs to where it would never be at that position, it would maybe pass over it.

1 Like

even if you didn’t need them, I still fixed that part of the code

try this then

``````local car = game.Workspace.deliverycar1
local position = Vector3.new(164.244, 3.919, -35.681)
local maxMagnitude = 3

if (position - car.PrimaryPart.CFrame.Position).Magnitude >= maxMagnitude then
eggs.Value -= 100
cash.Value += 100
end
``````

change maxMagnitude to how far the car can be from the variable position, I have it set to 3

also you can obviously change the variable names, I assumed you wanted camelCase

you would have to have something run every now and then to check the if statement later on, so the code actually runs

Well you see, I can’t determine what position it touches. Like, I don’t know if it ever even touches Vector3.new(164.244, 3.919, -35.681)

1 Like

you could make maxMagnitude 0

even then if you want it to be exact just do

``````if position1 = position2 then
end``````

What would changing the max magnitude even do to solve my problem? And it doesn’t have to be exact.

1 Like

like I said

if it is 0 then obviously it will be at that position, makes sense

either way if you have your if statement you still need a loop or event to check if the statement is true or not

I only showed magnitude earlier because I didn’t know if you wanted the position to be exact or not

Ok, I’m so lost, all I wanted is that when the car is at or near a position it gives you money.

1 Like

I literally gave you a magnitude script, isn’t that good enough then?

Script to move the car:

``````local  Model = script.Parent

while wait() do
Model:SetPrimaryPartCFrame(Model:GetPrimaryPartCFrame() * CFrame.new(1,0,0 + -.0000001))
end

``````
1 Like

Ok I literally can’t edit this, thought you were someone else because I saw someone else typing

literally no edit button at all

Well, it doesn’t have to be near, I was just saying that it doesn’t have to be 100% exact either. Also, I have no idea how to use magnitude in my script, and to be honest, I don’t even know what magnitude even means.

1 Like

Personally I think Tweening would work here
I also agree with @D0RYU. (Using a magnitude script like the one he gave here)

it is how far a position is from another position, which is why I showed it

1 Like

Yeah but I don’t know where to put it in my script
just know that I started scripting 6 months ago.

1 Like

You’ll have to find the magnitude between the 2 models’ positions. If they are less than a certain radius, you do something.

Here’s the visualization:

m1 is a model and m2 is the other model. ma is the magnitude between their positions. If the magnitude is less than some radius value, then the models are close to each other.

could we see the full script, kind of curious because of the “end)”
I want to know what event you are using