Script Description: Access Control to Restricted Areas
This script manages access to specific areas in a Roblox game. It allows or denies entry to players based on criteria such as belonging to a specific group or being part of a designated team. Key features include group or team-based authorization, the implementation of a cooldown to prevent repeated access, and the ability to make the Part
traversable without changing the player’s position. Ideal for games with restricted areas like VIP rooms or exclusive team zones. Provides a detailed log of accesses and attempts in the output console. Easily configurable by assigning the group ID, team name, and cooldown time. This script offers precise and secure control over access to specific areas, enhancing the player experience.
Script:
local groupId = 12345789 -- You can input your group ID, and if you don't have one, put nil.
local teamName = "TeamNameHere" -- Replace this with your team name.
local cooldownTime = 5 -- Time in seconds for the cooldown
local cooldownList = {} -- List ready to track the waiting time of each player.
local lastPrintedMessage = "" -- Saves the last printed message
--[[
-----------------------------------------------------
Sparkles, Access Control to Restricted Areas - v1.0.0
-----------------------------------------------------
WARNING, DO NOT MODIFY ANYTHING BELOW UNLESS YOU KNOW WHAT YOU'RE DOING.
For bugs, contact @sparklesyroblox on Discord.
]]
-- Function to print messages with a delay.
local function imprimirMensaje(mensaje)
if mensaje ~= lastPrintedMessage then
print(mensaje)
lastPrintedMessage = mensaje
end
end
-- Function to handle player touch on the Part.
local function onTouch(hit)
local character = hit.Parent
if character and character:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(character)
if player then
-- Check if the player is on cooldown.
local currentTime = tick()
local lastCooldownTime = cooldownList[player.UserId] or 0
if (currentTime - lastCooldownTime) >= cooldownTime then
local isAuthorized = false
if groupId == nil then
isAuthorized = true
else
-- Check if the player belongs to the group selected above.
local success, isMember = pcall(function()
return player:IsInGroup(groupId)
end)
if success and isMember then
isAuthorized = true
end
end
-- Check if the player has the team selected above.
local playerTeam = player.Team
if playerTeam and playerTeam.Name == teamName then
isAuthorized = true
end
if isAuthorized then
-- Player is authorized, allow access.
imprimirMensaje(player.Name .. " (" .. player.UserId .. ") He accessed " .. script.Parent.Name .. " with authorization.")
-- Make the Part traversable by the authorized player.
script.Parent.CanCollide = false
else
-- Player is not authorized, reset player.
imprimirMensaje(player.Name .. " (" .. player.UserId .. ") It was reset for attempting to access " .. script.Parent.Name .. " unauthorized.")
character:BreakJoints()
end
cooldownList[player.UserId] = currentTime
else
imprimirMensaje(player.Name .. " (" .. player.UserId .. ") Attempted to accesss " .. script.Parent.Name .. " during the cooldown.")
end
end
end
end
local function onTouchEnded(hit)
local character = hit.Parent
if character and character:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(character)
if player then
-- Restore the Part to its normal state.
script.Parent.CanCollide = true
end
end
end
-- Connect the functions to the Touched and TouchEnded events
script.Parent.Touched:Connect(onTouch)
script.Parent.TouchEnded:Connect(onTouchEnded)
- Yes
- No
0 voters
- Yes
- No
0 voters