I have to calculate a position in-between a tower and an enemy. This is the code
local tower = script.Parent local enemy = workspace.Enemy
local distance = tower.Position - enemy.Position
print(distance)
Is it because the tower I made comes from the Rig maker or am I just not coding right?
The error is letting you know that you're attempting to grab the Position of a Model rather than a BasePart. I don't have prior knowledge of the contents of your model, but in this situation it is ideal to set the PrimaryPart property of the model to be the tower's main (biggest?) part. Then to get the distance between the tower and an enemy, you could get the difference between the two position vectors and use its magnitude!
local tower = script.Parent local enemy = workspace.Enemy local distance = tower.PrimaryPart.Position - enemy.PrimaryPart.Position -- Here I am assuming enemy is a model. If it is not, then you can remove the PrimayPart part I used print(distance.Magnitude.." studs") -- This is always in studs
Model
instances do not have a Position
field. What you can do is use the PrimaryPart
field of your Model
.
Something like: tower.PrimaryPart.Position
would suffice so long as you set the PrimaryPart
via Script
or using the Properties viewer in Studio.