Hi there,
I've created a local script that is located in the players StarterGui; basically what it does is whenever you hover over any part called 'Door' in the workspace, a GUI becomes visible if you are within a defined distance (the end product will move the part horizontally when you press a key).
I'm having trouble with getting the GUI to appear for multiple parts named 'Door'. Currently I have two parts in my game named 'Door'; however, when moused over, only one of the parts displays the GUI. Nothing happens when I mouse over the other part named door, not even the print("moused over").
I'd really appreciate some help! I've been on this game for several years now but have never really made my own code.
Thanks!
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local door = game.Workspace.Door
distance = 10
function doorOpen()
end
function doorLock()
end
Mouse.Move:connect(function()
local target = Mouse.Target
if target == door then --strange error happening here but still works
print("moused over")
if (Player.Character.Torso.Position - door.Position).magnitude <= distance then
script.Parent.Visible = true;
print(target.Owner.Value)
else
script.Parent.Visible = false;
end
else
script.Parent.Visible = false;
end
end)

3 comments
This seems to have worked, thanks! But I'm getting an error whenever I'm not moused over a door: Players.Player1.PlayerGui.DoorGui.Frame.DoorScript:17: attempt to index local 'target' (a nil value)
This is because when you're not pointing at anything, "target" returns nil. All you need to do is add another "if...then" statement to check whether it is nil.
It works now, thank you!