Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why isnt the second chest opening?

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)

2 comments

0

Move Chests[1]:Destroy() to line 09

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...

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.