Making a Detection Script for a Door

Hello everyone!

This is me DragonDarkVader!

I’m almost done making my horror game, A little bit of Adding and Tweeking and then i will release it

One thing i’m stuck with is the Crouching System and Detection script.

I’d like to make one similar to Doors and Break-In Story

Like if you hit the Detector Part, You will be placed inside the room

Here is the Picture of the door i made if your confused.

Once the Room is full to 12, the Door will Close and tp’s the Players to the Game which is this game ID 11047724801

And the countdown is like 20 to 1, If the Room is not full and the time ran out, Then they will be force teleported to the Game and Play.

But once the Player Leaves the Room, The Timer Resets.

EDIT: I tried asking all of my friends. But there Offline. I got one friend to help, But he’s busy on School…So that’s why i’m forced to ask on DevForum.

You could add a touched event to the detector part, and have a variable keeping track of how many players are currently inside of the room. Once you have your minimum number of players, you could make a for loop that counts down and breaks when someone exits. To track exits, you could either have an exit button, or another part with a touched event.

2 Likes

Put a part in the middle of the room and put this script inside of the detection door.

local pos = (part in middle of room).Position

script.Parent.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
part.Parent:MoveTo(pos)
end
end)

So i need to create a RemoteEvent on ReplicatedStorage?

You could have the touched event on the server and have it handle it. Depending on how you want to spread the workload, you could have it on the client and use remote events instead.

1 Like

The script I gave you Is bear bones you will need to use multiple remote events for countdown and activating/deactivating it

Ok, I added one RemoteEvent inside ReplicatedStorage

EDIT: I named it DetectionDoor.

how many RemoteEvents? character limit

I am not scripting your game for you, are you sure you have at least a basic understanding of Roblox coding?

I have basics on it, But this. I think i cannot handle it

Image
Full

I just learned like a week ago? idk

All i know is how to make a Close/Open local script and how to set the Baseplate in Color Red and Delete the Textures and it’s Transparency.

If you want to do it the easiest way, you could just put a part in where they stand when they enter and have the following code on the server.

local curPlayers = {}
local counting = false
local curNum = 30
function count()
    for I = 1,30 do
        if counting then
            wait(1)
            curNum -= 1
end
game.Workspace.partNameHere.Touched:Connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") then
        local plr = game.Players:GetPlayerFromCharacter(part.Parent)
        if plr ~= nil then
            table.insert(curPlayers, plr)
            -- Make an if statement to check if you need to run a function that starts the countdown.
        end
    end
end)

-- You could do something a bit like this on the server.

There is a bit of a start. I hope it helps.

So i’m guessing that goes in a Script on ServerScriptService?

It is not the full script, but it is a start. It does go there. The current script will not properly function on its own, but I think you should look into it and see what you think the next step is. I am not making scripts for you, but I am giving you part of a script so that you can continue on with the basic start.

This is not a full script, you can’t just copy and paste it into you game, you need to expand on it to work what you want it to do.

It says on your profile you have about 1.2 years of dev experience. You still, however, don’t know how to make a simple countdown script?

The room virtually is a rectangule with coordinates. How about creating a script that every, let’s say, 0.3 seconds checks coordinates of all the players in the game. And if a player’s coodinates fall withing the coordinates of the room, then your body-count can be counted as +1.
In the game you have to work out situation in case more than 12 players sneak in… what if 20?! Try to manage a queue system to detect who was the last… Just kill them HAHAHA if they sneak in.

Oh sorry about that i was AFK, From the thing i meant on 1.2 Years of Experience is on Building and Roblox Studio Methods.

made a similar design before and it doesnt take much at all
just use the zoneplus module if there are 12 players inside the zone you simply teleport
of course if you dont want more 12 people inside at once you can make the doors cancollide to true

1 Like