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

Script not working? Needing help with magnitude. It keeps printing nil!!

Asked by 4 years ago
Edited 4 years ago

I have been trying to use magnitude but I don't quite understand how to use it. Help would be amazing! (: Here is my script.

local MyTorso = script.Parent:WaitForChild("UpperTorso")

function FindPlayer()
    local Distance = 9999
    local Target = nil
    for i, v in pairs(workspace:GetChildren()) do
        local TargetHumanoid = v:FindFirstChild("Humanoid")
        local TargetTorso = v:FindFirstChild("UpperTorso")
        if TargetHumanoid and TargetTorso then
            if (MyTorso.Position - TargetTorso.Position).magnitude < Distance then
                Distance = (MyTorso.Position - TargetTorso.Position).magnitude
                Target = TargetTorso
            end
        end
    end
end

while wait(2) do
    local Torso = FindPlayer()
    print(Torso)
end

Thanks in advance.

0
You did not return anything. Optikk 499 — 4y
0
Omg!! Thank you so much. THAT REALLY HELPS!!! ScriptedEli 101 — 4y

Answer this question