Script doesnt always work

ok so i have a problem with my script that teleports players to a planet at a certain height
sometimes it doesnt show the gui for some players and sometimes it does how can i fix this?

local plrService = game:GetService(“Players”)
local plr = plrService.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
print("player addded "…tostring(plr.Name))

while true do
wait()

  if char.HumanoidRootPart.Position.Y > 199999  then
  	script.Parent.Visible = true
  		script.Parent.TextLabel.Visible = true
  		
  else
  	script.Parent.Visible = false
  	script.Parent.TextLabel.Visible = false

end
end

Not sure if this will work but you can try

while true do
	wait()
	char.Humanoid:GetPropertyChangedSignal("Position"):Connect(function()
		if char.HumanoidRootPart.Position.Y > 199999 then
			script.Parent.Visible = true
		end
	end)
end

I think you just need to use CFrame to find the Y.

Change it to this
if char.HumanoidRootPart.CFrame.Y > 199999 then

Hope this helps

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")


Player.CharacterAdded:Connect(function(_Character)
	Character = _Character
	HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
end)


game:GetService("RunService").RenderStepped:Connect(function()
	if Character then
		if HumanoidRootPart then
			if Character.HumanoidRootPart.Position.Y > 199999  then
				script.Parent.Visible = true
				script.Parent.TextLabel.Visible = true
			else
				script.Parent.Visible = false
				script.Parent.TextLabel.Visible = false
			end
		end
	end
end)

but what is the difference? don’t they do the same thing here?