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)
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.
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
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.
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.