This script is supposed to open/close a player's GUI via a remote function, depending on how close the player is (or isn't) to a particular block. It's in a model that is bought in a tycoon game.
The script runs perfectly when there is only one of the brick present in the game. Any more and the script breaks. Besides this, Output gave me nothing.
Can someone help me? Here's the script:
exited = {}
while wait() do
local armsPos = script.Parent.Torso.Position
for _,v in pairs(game.Players:GetPlayers()) do
if v.Character ~= nil and (armsPos - v.Character.Torso.Position).magnitude <= 10 and not exited[v.Name] then
game.ReplicatedStorage.ShowArmory:FireClient(v,true)
exited[v.Name] = true
elseif v.Character ~= nil and (armsPos - v.Character.Torso.Position).magnitude > 10 then
game.ReplicatedStorage.ShowArmory:FireClient(v,false)
if exited[v.Name] then exited[v.Name] = nil end
end
end
end
If it matters, here is the section of the script, located in the GUI itself, that detects whether or not it should be visible.
game.ReplicatedStorage.ShowArmory.OnClientEvent:connect(function(val)
gui.Enabled = val
end)

1 comment
it works with either line.