Play animation when you're x studs away from npc

So i have an npc and want it to play an animation when the player is x studs away from it, but don’t really know how to make it

Well, you can make use of Magnitude (or the search bar).

Basically, Magnitude checks the distance between 2 locations in studs(the Unit of measurement Roblox uses):

RunService.Heartbeat:Connect(function() -- Run every frame
    if (Player.Position - NPC.Position).Magnitude <= 50 then
        -- Do something
    end
end)
5 Likes