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

Multiple keys to unlock 1 box, how to expand on my script?

Hello. So i am trying to make a lock box, where u need 5 keys in order to open the box. This is the script to destroy on of the locks:

script.Parent.Touched:Connect(function(p)
	if p.Parent.Name == "Key1" then
		script.Parent:Destroy()
	end
end)

So i wanna take that script and make it so u need to destroy 5 locks in order to open up the box containing the other tools. The box is name "BoxTop" and i need keys named Key1-Key5. If this is confusing please feel free to ask what i am trying to do!

1 answer

✓ Accepted answer

Here, i use multiple if statements to know if the player is putting the keys in a order. Name the keys Key1, Key2, Key3, Key4 and Key5, and you should be fine.

script.Parent.Touched:Connect(function(p)
    if p.Parent.Name == "Key1" then
        if p.Parent.Name == "Key2" then
            if p.Parent.Name == "Key3" then
                if p.Parent.Name == "Key4" then
                    if p.Parent.Name == "Key5" then
                        script.Parent:Destroy()
                              end
                        end
                  end
            end
      end
end)

Hopefully i helped, and if i did, please click the button "acept answer".

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