Yes I know the title sounds confusing. However, hear me out. I want to have a secret room door similar to the one in Epic Minigames that opens when you click all the hats. The door should only be open for the player who clicked the hats, and closed for everyone else. How would I do this? I would also love examples, too. All help is appreciated!
You can open the door utilizing a LocalScript to replicate it only on the Client
To make something like this, put a local script in starter character with these contents (assuming you’re using hats)
local code:
local hats = workspace.Hats -- put all hats here
local clicked_hats = {}
for i, v in hats:GetChildren() do
local click_detector = v:FindFirstChildOfClass("ClickDetector") or Instance.new("ClickDetector", v)
if not clicked_hats[v] then
click_detector.MouseClick:Connect(function()
clicked_hats[v] = v
if #clicked_hats >= #hats:GetChildren() then
--- open door
end
end)
end
end
A simple way to do this is:
- Make some server code that checks if the player clicks all the hats (or etc.). If they do, fire a RemoteEvent
- Put a Script set to client run context inside the door (in properties of a Script). Have the script get the remote event from ReplicatedStorage and when the event fires for the client just have the script open the door.
If you want to make it exploiter proof you can also have code with the server code that teleports players who haven’t clicked all the hats out of the room (that’s why I prefer to have that kind of code on the server instead of the client).
Roblox added a new property called RunContext to the scripts, so now developers can run LocalScripts outside of StarterGui / StarterPlayer etc.
- Insert a normal script
- Set its RunContext to Client
- Now that script can run anywhere like Workspace, and it’ll be a Client-Sided script.
- Add a ClickDetector inside your hats
- Write a simpe script like @Marusenai’s script
Okay, this is what I have on now. The script seems to work. There are no errors in the output and yet even after clicking the hats the door doesnt open at all.
local hats = game.Workspace.Lobby.Hats -- put all hats here
local clicked_hats = {}
for i, v in hats:GetChildren() do
local click_detector = v:FindFirstChildOfClass("ClickDetector")
if not clicked_hats[v] then
click_detector.MouseClick:Connect(function()
clicked_hats[v] = v
if #clicked_hats >= #hats:GetChildren() then
game.Workspace.Lobby["Main Walls"].HiddenDoor.Position = Vector3.new(-44.712, 78, 129.482)
game.Workspace.Lobby["Main Walls"].HiddenDoor.Transparency = 1
end
end)
end
end
Put a print statement where you try to open the door, then check if it prints anything
I just tried, nothing prints at all. But I have an idea. Maybe the button itself isnt triggering for some reason. I have a clickdetector inside it with a script that has its runcontext to client, with this code inside.
script.Parent.MouseClick:Connect(function()
print("Clicked!")
script.ClickedValue.Value = true
script.Click:Play()
end)
It works, but the door doesnt open.
Oh I figured out a solution. Thanks