I want the function to print("HERE") when the brick is 5 studs away, but when I print the magnitude the value is returning the same everytime the player moves closer to the part. Please help. wait(1)
plr = game.Workspace:findFirstChild(game.Workspace.PlayerName.Value)-- The player pt1 = plr.Torso.Position mag = (pt1 - script.Parent.Position).magnitude plr.Humanoid.Running:connect(function(speed) print(mag) if mag <= 15 then print("HERE") end end)
The problem here is that pt1
holds the instantaneous Position of plr.Torso
. What this means is that pt1
isn't up to date.
Change lines 2 and 3 to fix:
pt1 = plr.Torso mag = (pt1.Position - script.Parent.Position).magnitude