I have tried every radius like script to magnitude to finding the nearest torso. I'm trying to make a script which if a player gets inside of a certain radius to a block it will give them a GUI, Make them speak and give them an item but this script wont work. (BY THE WAY, this is a SCP script called SCP-3020 - Depression so don't mind the text)
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 50
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("Torso")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while true do
wait(0.1)
local target = findNearestTorso(script.Parent.Top.Position)
if target ~= nil then
targ = target
hum = targ.Parent:findFirstChild("Humanoid")
if (hum == nil) then
script.Parent.Head.Fail:play()
end
local char = hum.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local Lonely = plr.PlayerGui.Lonely
wait(40)
enabled = true
end
end
Using this script I try to make it so it makes them speak.

5 comments
This is not a asking question to get a new script I'm just wondering if there is a way to fix it or not.
What goes wrong with the script you posted?
It doesn't work...
https://www.youtube.com/watch?v=p9GVCfgHrzY You're bringing everyone down!
Man sorry.