Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help on magnitude?

Asked by
Adryin 120
9 years ago

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

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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
0
I'll try Adryin 120 — 9y
0
Thanks Adryin 120 — 9y
Ad

Answer this question