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

"Is in range" prints on spawn, i'm trying to get it to print when im 20 studs away?

local player = game.Players.LocalPlayer
local hats = game.Workspace.Configuration.Dominus
local maxpickup = 20
local distance = player:DistanceFromCharacter(hats.Position)


if distance <= 20 then

print("Is in range")

end

1 answer

You have to keep updating the distance, and avoid using DistanceFromCharacter, its unreliable as it takes distance from the character's head. Try doing this:

local player = game.Players.LocalPlayer
local character = player.Character
local hats = game.Workspace:WaitForChild("Configuration"):FindFirstChild("Dominus")
local maxpickup = 20

function CheckDistance(a,b)
	return (a.Position -  b.Position).magnitude
end
Game:GetService("RunService").RenderStepped:Connect(function(dt)
	if CheckDistance(character.PrimaryPart,hats.Handle) < maxpickup then
		print("Is in range")
	end
end)

Comment if any problem, i will try to fix.

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