I have made an interaction script which will display a BillboardGui when in a certain range of the door scanner and get deleted when away from it and in the upper part is how the whole interaction system works itself.
I found this system to be working until I would place 2 scanners on each side of the wall where I would get 2 BillboardGuis popping up and be able to interact with the scanner from the other side, is there any sort of way to make both of these work to the closest scanner to the player?
local userInputService = game:GetService("UserInputService")
local allScanners = game.Workspace.Scanners
local Camera = game.Workspace.CurrentCamera
userInputService.InputBegan:Connect(function(inputObject, gameProcessed)
if gameProcessed then return end
if inputObject.KeyCode == Enum.KeyCode.E then
for _, scanner in next, allScanners:GetChildren() do
if (scanner.Center.Position - game.Players.LocalPlayer.Character.UpperTorso.Position).Magnitude <= 9 then
scanner.ScannerEvent:FireServer()
end
end
end
end)
while true do
for _, scanner in next, allScanners:GetChildren() do
if (scanner.Center.Position - game.Players.LocalPlayer.Character.UpperTorso.Position).Magnitude < 9 then
if scanner.Center:FindFirstChild("BillboardGui") == nil then
game.ReplicatedStorage.BillboardGui:Clone().Parent = scanner.Center
if (scanner.Center.Position - game.Players.LocalPlayer.Character.UpperTorso.Position).Magnitude > 9 then
scanner.Center:FindFirstChild("BillboardGui"):Destroy()
end
end
end
end
wait(0.5)
end