Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why isnt the second chest opening?

Asked by 2 years ago

why isnt the second chest opening?

local Chests = {game.Workspace.Chests.Chest1, game.Workspace.Chests.Chest2}
local OpenChests = {game.ServerStorage.Chests.Game.OpenChest1, game.ServerStorage.Chests.Game.OpenChest1}

Chests[1].KeyHole.ClickDetector.MouseClick:Connect(function()
    Chests[1]:Destroy()
    OpenChests[1]:Clone().Parent = game.Workspace
    table.remove(Chests, 1)
    table.remove(OpenChests, 1)
    print(Chests[1])
end)
0
Move Chests[1]:Destroy() to line 09 9mze 193 — 2y
0
That didn't work, it destroyed the wrong one because it its removing 1 from the list and the list shifts over. so 2 becomes 1 and 3 becomes 2 ect... oligamingthebest 9 — 2y

1 answer

Log in to vote
0
Answered by
wf_sh 15
2 years ago
local OpenChests = {game.ServerStorage.Chests.Game.OpenChest1, game.ServerStorage.Chests.Game.OpenChest1}

Chest2 is not within your OpenChest table

Chests[1].KeyHole.ClickDetector.MouseClick:Connect(function()
    Chests[1]:Destroy()

Furthermore, you are only listening for the keyhole of the first chest to be clicked, of which is automatically disconnected once it's opened since you destroy the object anyway.

Ad

Answer this question