I have been trying to make a model move towards a player when the player enters a certain radius. To do this, I have created an invisible part for the radius and made it so when the player touches the radius, it runs a script that constantly changes the X, Y, and Z values until they are equal to the player’s, however when I do so it properly moves the models Primary Part to position, but it makes the model move infinitely high up in the sky.
Here is the script:
local primary = script.Parent.PrimaryPart
local children = script.Parent:GetChildren()
script.Parent.SwimRadius.Touched:Connect(function(otherPart)
local touched = false
if otherPart.Parent:FindFirstChild("Humanoid") then
while true do
if primary.Position.X == otherPart.Position.X then
elseif primary.Position.X > otherPart.Position.X then
primary.Position = primary.Position + Vector3.new(-1,0,0)
script.Parent:MoveTo(primary.Position)
elseif primary.Position.X < otherPart.Position.X then
primary.Position = primary.Position + Vector3.new(1,0,0)
script.Parent:MoveTo(primary.Position)
end
if primary.Position.Y == otherPart.Position.Y then
elseif primary.Position.Y > otherPart.Position.Y then
primary.Position = primary.Position + Vector3.new(0,-1,0)
script.Parent:MoveTo(primary.Position)
elseif primary.Position.Y < otherPart.Position.Y then
primary.Position = primary.Position + Vector3.new(0,1,0)
script.Parent:MoveTo(primary.Position)
end
if primary.Position.Z == otherPart.Position.Z then
elseif primary.Position.Z > otherPart.Position.Z then
primary.Position = primary.Position + Vector3.new(0,0,-1)
script.Parent:MoveTo(primary.Position)
elseif primary.Position.Z < otherPart.Position.Z then
primary.Position = primary.Position + Vector3.new(0,0,1)
script.Parent:MoveTo(primary.Position)
end
wait(1)
end
end
end)
Here is what the script does instead of moving the part to the player’s position: