I want to make me show a gui when I go to the doors or windows
but, the code looks for a door or window at random then only the gui appears on a door or window, I would like to know how I can repair. the code is here:
(i tried to fix it but i dont know how)
while wait() do
for _,Magnitude in pairs(game.Workspace.GameStuffs.MagnitudeStuffs:GetChildren()) do
local Mag1 = (Magnitude.Center1.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
local Mag2 = (Magnitude.Center2.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
print(Mag1)
print(Mag2)
if Mag1 <= Magnitude.Range.Value and Magnitude.Center1.OnOrOff.Value == true or Mag2 <= Magnitude.Range.Value and Magnitude.Center2.OnOrOff.Value == true then
script.Parent.TextLabel.Visible = true
script.Parent.TextLabel.Text = "'E' to interact"
print("working")
break
else
print("stop")
script.Parent.TextLabel.Visible = false
break
end
end
end
hre is the code if someone need fix the same problem:
while wait() do
for _,Magnitude in pairs(game.Workspace.GameStuffs.MagnitudeStuffs:GetChildren()) do
local Mag1 = (Magnitude.Center1.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
local Mag2 = (Magnitude.Center2.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if Mag1 <= Magnitude.Range.Value and Magnitude.Center1.OnOrOff.Value == true or Mag2 <= Magnitude.Range.Value and Magnitude.Center2.OnOrOff.Value == true then
script.Parent.TextLabel.Visible = true
script.Parent.TextLabel.Text = "'E' to interact"
print("working")
break
elseif Mag1 > Magnitude.Range.Value and Mag2 > Magnitude.Range.Value then --Problem
print("stop")
script.Parent.TextLabel.Visible = false
end
end
end