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

[Solved] How can I make a clickable door that can be opened only if you have an object in inventory?

About 3 days ago I created a door that opens by clicking on it. But I'm looking for a way to make the door open only for players who have a key in their hotbar (You don't have to have the key in your hand, you only need to have it in the hotbar). Can someone help me?

ClickDetector Script:

function onClicked()
	if script.Parent.Parent.Active.Value == false then
		script.Parent.Parent.Active.Value = true
		script.Parent.Sound.Playing = true
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

If you need the door script let me know.

1 answer

✓ Accepted answer

First you need to get the player clicking the part by doing onClicked(player), then checking if the key is in the player's backpack.

function onClicked(player)
    if player.Backpack:FindFirstChild("EnterTheKeyNameHere") then
    	if script.Parent.Parent.Active.Value == false then
		    script.Parent.Parent.Active.Value = true
		    script.Parent.Sound.Playing = true
    	end
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

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