I’m making a script where if your close enough to an npc a gui will pop up and text will apear on it but the gui will not appear nor disapear.
2 Likes
You’re on the right track, you need to be frequently checking the distance not just checking it once when the script first executes.
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local screenGui = script.Parent
local npc = workspace.NPC
while true do
task.wait(1) --change this if necessary
local distance = (npc.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude
if distance > 6 then
screenGui.Enabled = false
else
screenGui.Enabled = true
end
end
2 Likes
Its working now thanks for the help!
Like @Forummer said, you need to check it frequently. He used a while true do
loop, though I would recommend using RunService.Renderstepped.
Code:
game:GetService("RunService").RenderStepped:Connect(function()
local distance = (npc.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude
if distance > 6 then
screenGui.Enabled = false
else
screenGui.Enabled = true
end
end)
Don’t give me the solution
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.