while true do for i,plr in ipairs(game.Players:GetChildren()) do local char=plr.Character print("works") if char~=nil then local t=char:FindFirstChild("Torso") local h=char:FindFirstChild("Humanoid") if t~=nil and h~=nil then if h.Health>0 then pos1=t.Position*Vector3.new(1,0,1) pos2=script.Parent.Base.Position*Vector3.new(1,0,1) if (pos1-pos2).magnitude<10 then print((pos1-pos2).magnitude) print("I'm close enough") game.StarterGui.ScreenGui.Enabled=true print("Screengui should be enabled") else print("I'm not close enough") game.StarterGui.ScreenGui.Enabled=false end end end end end wait(1) end
What this script does is checks your distance every second, if the distance is less than 10, a screen gui should enable, but it doesen't - any idea why?
Try enabling the Gui through the Player's PlayerGui? If you need me to elaborate more I'd happily connect with you.
If this doesn't solve the issue, I'll properly debug the issue. (I haven't tested the script; but have had past experiences with problems occurring like this.)
plr.PlayerGui:WaitForChild("ScreenGui").Enabled = true -- true / false