Hello,
I have a problem with my script, the BulidMode function fires itself when the exitBulidMode function is running. skyrpt is chaotic because I was looking for why this is happening
in addition, this error only occurs when ACTIVATING BulidModeDisbale
if I activate ExitBulidMode, everything works normally
wait(3)
BulidMode()
wait(10)
ExitBulidMode()
local script
local Camera = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local Bulid = game.ReplicatedStorage.Remotes.Bulid
local RemoveObj = game.ReplicatedStorage.Remotes.RemoveObj
local ConnectionsM = {}
local ConnectionsE = {}
local ConnectionsR = {}
function ExitBulidMode()
plr.PlayerGui.Manager.BulidModeDisbale.Visible = false
wait(3)
for _, v in pairs(workspace.Map.Hall1:GetDescendants()) do
if v.Name == "ExtraSlot" or v.Parent ~= nil and v.Parent.Name == "MachineSlots" then
v.Transparency = 1
local clickDetector = v:FindFirstChildOfClass("ClickDetector")
if clickDetector then
clickDetector:Destroy()
end
end
end
end
function BulidMode()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = workspace.Map.Hall1.StartPart1.Conveyor.CamPos.CFrame
for _,v in pairs(workspace.Map.Hall1:GetDescendants()) do
if v.Name == "ExtraSlot" or v.Parent.Name == "MachineSlots" then
v.Transparency = 0.5
if (v.Name == "ExtraSlot" or v.Parent.Name == "MachineSlots") and v:GetAttribute("Used") == true then
v.BrickColor = BrickColor.new("Really red")
elseif v.Name == "ExtraSlot" then
v.BrickColor = BrickColor.new("Bright yellow")
elseif v.Parent.Name == "MechineSlots" then
v.BrickColor = BrickColor.new("Sea green")
end
local ClickDetector = Instance.new("ClickDetector", v)
ClickDetector.MaxActivationDistance = "inf"
ClickDetector.MouseClick:Connect(function()
if v.Name == "ExtraSlot" and ClickDetector.Parent:GetAttribute("Used") == false then
BulidExtra(v)
elseif v.Parent.Name == "MachineSlots" and v:GetAttribute("Used") == false then
ClearConnections(ConnectionsM)
BulidMachine(v)
else
ClearConnections(ConnectionsR)
Remove(v)
end
end)
end
end
end
function BulidExtra(Slot)
plr.PlayerGui.Manager.ExtraInv.Visible = true
for _,v in pairs(plr.PlayerGui.Manager.ExtraInv.Grid:GetChildren()) do
if v:IsA("TextButton") or v:IsA("ImageButton") then
local fun = v.MouseButton1Click:Connect(function()
if workspace.FactoryInv:FindFirstChild(v.Name).Value > 0 then
Bulid:FireServer(Slot,v.Name)
plr.PlayerGui.Manager.ExtraInv.Visible = false
Reload()
ClearConnections(ConnectionsE)
end
end)
table.insert(ConnectionsE, fun)
end
end
end
function BulidMachine(Slot)
plr.PlayerGui.Manager.DropperInv.Visible = true
for _,v in pairs(plr.PlayerGui.Manager.DropperInv.Grid:GetChildren()) do
if v:IsA("TextButton") or v:IsA("ImageButton") then
local fun = v.MouseButton1Click:Connect(function()
if workspace.FactoryInv:FindFirstChild(v.Name).Value > 0 then
Bulid:FireServer(Slot,v.Name)
plr.PlayerGui.Manager.DropperInv.Visible = false
Reload()
ClearConnections(ConnectionsM)
end
end)
table.insert(ConnectionsM, fun)
end
end
end
function Remove(Slot)
plr.PlayerGui.Manager.RemoveFrame.Visible = true
local fun = plr.PlayerGui.Manager.RemoveFrame.Cancel.MouseButton1Click:Connect(function()
plr.PlayerGui.Manager.RemoveFrame.Visible = false
end)
table.insert(ConnectionsR, fun)
local fun = plr.PlayerGui.Manager.RemoveFrame.RemoveObj.MouseButton1Click:Connect(function()
RemoveObj:FireServer(Slot)
plr.PlayerGui.Manager.RemoveFrame.Visible = false
Reload()
end)
table.insert(ConnectionsR, fun)
end
function ClearConnections(connections)
for _, connection in ipairs(connections) do
connection:Disconnect()
end
connections = {}
end
function Reload()
wait(0.15)
for _,v in pairs(workspace.Map.Hall1:GetDescendants()) do
if (v.Name == "ExtraSlot" or v.Parent.Name == "MachineSlots") and v:GetAttribute("Used") == true then
v.BrickColor = BrickColor.new("Really red")
elseif v.Name == "ExtraSlot" then
v.BrickColor = BrickColor.new("Bright yellow")
elseif v.Parent.Name == "MechineSlots" then
v.BrickColor = BrickColor.new("Sea green")
end
end
BulidMode()
end
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Visible = false
plr.PlayerGui.Manager.BulidModeDisbale.Visible = true
end)
plr.PlayerGui.Manager.BulidModeDisbale.MouseButton1Click:Connect(ExitBulidMode)
plr.PlayerGui.Manager.DropperInv.Exit.MouseButton1Click:Connect(function()
plr.PlayerGui.Manager.DropperInv.Visible = false
ClearConnections(ConnectionsM)
end)
plr.PlayerGui.Manager.ExtraInv.Exit.MouseButton1Click:Connect(function()
plr.PlayerGui.Manager.ExtraInv.Visible = false
ClearConnections(ConnectionsE)
end)
wait(3)
BulidMode()