Certainly! Below are example scripts for opening and closing a base in Roblox, similar to what you might see in "Steal a Brainrot" game. These scripts utilize Roblox's ServerScriptService and ProximityPrompt to allow players to interact with the base.
Open Script (ServerScript)
Place this script in ServerScriptService and name it BaseOpenScript.
lua
-- BaseOpenScript in ServerScriptService
-- Get the base model and the ProximityPrompt
local baseModel = workspace:WaitForChild("Base") -- Change "Base" to the name of your base model
local openPrompt = baseModel:WaitForChild("OpenPrompt") -- The ProximityPrompt for opening the base
local door = baseModel:WaitForChild("Door") -- The part that acts as the door
-- Function to open the base
local function openBase(player)
-- Check if the base is already open
if door.Position ~= door.OpenPosition then
-- Animate the door opening
local openPosition = door.OpenPosition -- Pre defined open position
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local goals = {Position = openPosition}
local tween = tweenService:Create(door, tweenInfo, goals)
tween:Play()
end
end
-- Connect the ProximityPrompt Triggered event to the openBase function
openPrompt.Triggered:Connect(openBase)
Close Script (ServerScript)
Place this script in ServerScriptService and name it BaseCloseScript.
lua
-- BaseCloseScript in ServerScriptService
-- Get the base model and the ProximityPrompt
local baseModel = workspace:WaitForChild("Base") -- Change "Base" to the name of your base model
local closePrompt = baseModel:WaitForChild("ClosePrompt") -- The ProximityPrompt for closing the base
local door = baseModel:WaitForChild("Door") -- The part that acts as the door
-- Function to close the base
local function closeBase(player)
-- Check if the base is already closed
if door.Position ~= door.ClosePosition then
-- Animate the door closing
local closePosition = door.ClosePosition -- Pre defined close position
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local goals = {Position = closePosition}
local tween = tweenService:Create(door, tweenInfo, goals)
tween:Play()
end
end
-- Connect the ProximityPrompt Triggered event to the closeBase function
closePrompt.Triggered:Connect(closeBase)
Setting Up the Base Model
Base Model:
Create a model in the workspace and name it Base.
Inside the Base model, create a part named Door. This will be the door that opens and closes.
Add two Position values to the Door part:
OpenPosition: Set this to the position where the door should be when open.
ClosePosition: Set this to the position where the door should be when closed.
Proximity Prompts:
Inside the Base model create a ProximityPrompt and name it OpenPrompt. Position it where players should stand to open the base.
Create another ProximityPrompt and name it ClosePrompt. Position it where players should stand to close the base.
Testing
Play-Test:
Click “Play” to test your game.
Stand near the OpenPrompt and press the prompted key to open the base.
Stand near the ClosePrompt and press the prompted key to close the base.
This setup will allow players to interact with the base to open and close it, similar to mechanics seen in games like "Steal a Brainrot".