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

Radius of a Player to a block?

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

0

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.

0

What goes wrong with the script you posted?

0

It doesn't work...

0

https://www.youtube.com/watch?v=p9GVCfgHrzY You're bringing everyone down!

0

Man sorry.

1 answer

✓ Accepted answer

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.

3 comments

0

ALOT of sites use the SCP

0

Thanks I will try

0

This doesn't work. When I get near the block it does not print anything the Part is named correctly but nothing works

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