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.
Something like this example is a good way to check if a player is within a radius of something: https://scriptinghelpers.org/questions/60744/best-way-to-check-if-a-player-is-within-radius-of-something#59095. You can manipulate it to create the region around the part rather than the player themselves if you want.
I get that the whole depression thing is part of the SCP, but just a heads up roblox probably wont allow it & will moderate your game.