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?

01local Chests = {game.Workspace.Chests.Chest1, game.Workspace.Chests.Chest2}
02local OpenChests = {game.ServerStorage.Chests.Game.OpenChest1, game.ServerStorage.Chests.Game.OpenChest1}
03 
04Chests[1].KeyHole.ClickDetector.MouseClick:Connect(function()
05    Chests[1]:Destroy()
06    OpenChests[1]:Clone().Parent = game.Workspace
07    table.remove(Chests, 1)
08    table.remove(OpenChests, 1)
09    print(Chests[1])
10end)
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
1local OpenChests = {game.ServerStorage.Chests.Game.OpenChest1, game.ServerStorage.Chests.Game.OpenChest1}

Chest2 is not within your OpenChest table

1Chests[1].KeyHole.ClickDetector.MouseClick:Connect(function()
2    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