Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help on magnitude?

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)

1 answer

✓ Accepted answer

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

2 comments

0

I'll try

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.