✓ Accepted answer
General Practice
Rather than use Torso, you can use the HumanoidRootPart of a Character since these exist in all Humanoid models, while Torso is only found in R6 models
connect is deprecated in favor of Connect
You should not use the parent parameter of Instance.new(), instead define the parent on a separate line
Creating a new Billboard per each Rendering will cause you too spam billboard guis, when you can check it there is one present using :FindFirstChild()
Use :WaitForChild() to make sure a part exists before using / changing it
Consider placing the LocalScript into the StarterGui (the below example specifies the part location rather than using it as a parent)
Issues
You are defining the magnitude of prior to the RenderStepped running, meaning it cannot change after its initial definition. To fix this, place the line of code within the function.
Revised Local Script under StarterGui
local plr = game:GetService("Players").LocalPlayer
local part = workspace:WaitForChild("Part")
local ReplicatedS = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService")
RS.RenderStepped:Connect(function()
local root = plr.Character:WaitForChild("HumanoidRootPart")
local radius = (root.Position - part.Position).magnitude
if radius <= 5 and part:FindFirstChild("BillboardGui") == nil then
local bg = Instance.new("BillboardGui")
bg.ExtentsOffset = Vector3.new(0, 15 ,0)
bg.Parent = part
local text = Instance.new("TextBox")
text.Text = "Test"
text.Parent = bg
end
end)
2 comments
Are you sure your character is R6 while testing? Torso is only available when the body rig is R6. Also, you should define radius IN the loop as currently your radius value is constant and is NOT updated on .RenderStepped
tried it with normal loop but its not working