why wont this work?
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local magnitude = (player.Character.Torso.Position - workspace.Door.Root.Position).magnitude p = 0 while wait() do if magnitude < 20 then p = 1 scrn = Instance.new("ScreenGui",player.PlayerGui) txt = Instance.new("TextLabel",scrn) txt.BackgroundTransparency = 1 txt.Text = "Click to open door." txt.Position = UDim2.new(0, 600,0, 500) txt.Size = UDim2.new(0, 500, 0, 50) txt.TextScaled = true txt.TextColor3 = BrickColor.new("White").Color end end
local player = game.Players.LocalPlayer local mouse = player:GetMouse() p = 0 function getDistance() return player.Character and player:DistanceFromCharacter(workspace.Door.Root.Position) or math.huge end while wait() do if getDistance() < 20 then p = 1 scrn = Instance.new("ScreenGui",player.PlayerGui) txt = Instance.new("TextLabel",scrn) txt.BackgroundTransparency = 1 txt.Text = "Click to open door." txt.Position = UDim2.new(0, 600,0, 500) txt.Size = UDim2.new(0, 500, 0, 50) txt.TextScaled = true txt.TextColor3 = BrickColor.new("White").Color end end
You were not updating the magnitude variable, so you were always checking the distance of the character's spawning location to the door's position. DistanceFromCharacter is also more efficient.