im making a hide and seek roblox game using luau
how can i add this into my game:
Hider/Seeker Selection
Pick 1 player to be Seeker
Others become Hiders.
Announce roles to each player:
“You are a Seeker!” or “You are a Hider!”
This is my main game loop script
-- Declared Variables
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local IntermissionTime = 5
local RoundTime = 10
local HidingTime = 5
local MinPlayers = 1
local VotingEvent = game.ReplicatedStorage:WaitForChild("Voting")
local UpdateVotes = game.ReplicatedStorage:WaitForChild("UpdateVotes")
local voteTime = 5
-- Declared Functions
local function TeleportPlayers(cframe) -- Teleport all players to a given CFrame
local players = Players:GetPlayers()
for i, player in players do
if not player.Character then continue end
code
player.Character:PivotTo(cframe)
end
end
local function Countdown(duration) -- Countdown for a given duration variable
for i = duration, 1, -1 do
workspace:SetAttribute("Clock", i)
task.wait(1)
end
end
local function Intermission()
print("Intermission")
workspace:SetAttribute("Status", "Intermission")
TeleportPlayers(workspace.IntermissionArea.SpawnLocation.CFrame * CFrame.new(0, 2, 0))
Countdown(IntermissionTime)
end
local function RunGame(map) -- Run the game with a given map
print("Game Begins")
TeleportPlayers(map.Spawn.CFrame)
workspace:SetAttribute("Status", "Time To Hide")
Countdown(HidingTime)
workspace:SetAttribute("Status", "Time remaining")
Countdown(RoundTime)
task.wait(1)
map:Destroy()
end
-- Game Loop
while true do
if #Players:GetPlayers() >= MinPlayers then
Intermission()
workspace:SetAttribute("Status", "Loading Map...")
print("New Game!")
code
-- Map voting
-- Declared Variables
local mapVotes = {}
local plrVotes = {}
local selectedMaps = {}
local currentMaps = game.ServerStorage.Maps:GetChildren()
for i = 1, 3 do
local newMap = currentMaps[math.random(#currentMaps)]
table.remove(currentMaps, table.find(currentMaps, newMap))
table.insert(selectedMaps, {
Name = newMap.Name,
Img = newMap:GetAttribute("MapImg")
})
mapVotes[newMap.Name] = 0
end
VotingEvent:FireAllClients(selectedMaps, voteTime)
UpdateVotes.OnServerInvoke = function(player, vote)
if vote then
local mapModel = game.ServerStorage.Maps:FindFirstChild(vote)
if not mapModel or not mapVotes[mapModel.Name] then
warn(tostring(vote).. " is not a votable map")
return mapVotes
end
local playerVote = plrVotes[player.UserId]
if playerVote then
mapVotes[playerVote] -= 1
end
plrVotes[player.UserId] = vote
mapVotes[vote] += 1
end
return mapVotes
end
task.wait(voteTime)
VotingEvent:FireAllClients(nil)
UpdateVotes.OnServerInvoke = nil
local chosenMap = nil
local highestVotes = 0
for name, votes in pairs(mapVotes) do
if votes >= highestVotes then
chosenMap = game.ServerStorage.Maps[name]
highestVotes = votes
end
end
print(chosenMap, "was picked")
task.wait(1)
local newMap = chosenMap:Clone()
newMap.Parent = workspace -- Map is spawned into workspace
-- local maps = ServerStorage.Maps:GetChildren()
-- local randomMap = maps[math.random(#maps)] -- Random map is chosen
-- local newMap = randomMap:Clone()
-- newMap.Parent = workspace -- Chosen Map is moved into workspace
-- task.wait(1)
RunGame(newMap) -- Players are teleported into the map
else
print("Waiting for players...")
workspace:SetAttribute("Status", "Waiting for players...")
task.wait(1)
end
end
this is my local script for game status gui
local gui = script.Parent
local function FormatTime(seconds) -- Format seconds as MM:SS
local minutes = math.floor(seconds / 60)
local remainingSeconds = seconds % 60
return string.format("%02d:%02d", minutes, remainingSeconds)
end
local function UpdateStatus() -- Update the GUI with the current status and time
local clockTime = workspace:GetAttribute("Clock")
local gameStatus = workspace:GetAttribute("Status")
code
if (gameStatus == "Time remaining" or gameStatus == "Intermission" or gameStatus == "Time To Hide") and clockTime then
gui.Display.StatusText.Text = gameStatus .. " : " .. FormatTime(clockTime)
else
gui.Display.StatusText.Text = gameStatus
end
To implement the Hider/Seeker selection and role announcements in your Roblox game, follow these steps:
1. Create a RemoteEvent for Role Announcements
In ReplicatedStorage, create a new RemoteEvent named RoleAnnouncement.
2. Server-Side Role Selection (Add to your main script)
Add this code inside your RunGame function, right after TeleportPlayers(map.Spawn.CFrame):
lua
-- Role selection and announcement
local players = Players:GetPlayers()
if #players < 1 then return end -- Safety check
-- Randomly select Seeker
local seekerIndex = math.random(1, #players)
local seeker = players[seekerIndex]
-- Assign roles
local roles = {}
for _, player in ipairs(players) do
roles[player] = if player == seeker then "Seeker" else "Hider"
end
-- Announce to clients
local RoleAnnouncement = game.ReplicatedStorage:WaitForChild("RoleAnnouncement")
for player, role in pairs(roles) do
RoleAnnouncement:FireClient(player, role)
end
3. Client-Side Role Display (Modify your LocalScript)
Add this to your existing LocalScript (in the GUI):
lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RoleAnnouncement = ReplicatedStorage:WaitForChild("RoleAnnouncement")
-- Add role display to GUI
local roleLabel = Instance.new("TextLabel")
roleLabel.Name = "RoleDisplay"
roleLabel.Size = UDim2.new(0, 200, 0, 50)
roleLabel.Position = UDim2.new(0.5, -100, 0.1, 0) -- Adjust position
roleLabel.BackgroundTransparency = 1
roleLabel.TextColor3 = Color3.new(1, 1, 1)
roleLabel.Font = Enum.Font.GothamBold
roleLabel.TextSize = 24
roleLabel.Parent = gui.Display -- Assuming 'Display' is a ScreenGui
RoleAnnouncement.OnClientEvent:Connect(function(role)
roleLabel.Text = "You are a " .. role .. "!"
-- Optional: Add animation/sound
end)
User
Visual Feedback: Add particle effects or sounds when roles are assigned (seeker has different particles effects and sounds compared to hiders)
Team Colors: Use player.Team to visually distinguish Seekers/Hiders and sort them into teams so you can see them on the leaderboard
change text colour red if player is seeker and text colour blue if player is hider
Assistant
Here's how to implement visual feedback, team colors, and role-based GUI colors:
1. Server-Side Team Setup (Add to your main script)
Add this at the top of your script with other variables:
lua
local Teams = game:GetService("Teams")
local function SetupTeams()
-- Create Seeker Team (Red)
local seekerTeam = Teams:FindFirstChild("Seeker")
if not seekerTeam then
seekerTeam = Instance.new("Team")
seekerTeam.Name = "Seeker"
seekerTeam.TeamColor = BrickColor.new("Bright red")
seekerTeam.AutoAssignable = false
seekerTeam.Parent = Teams
end
-- Create Hider Team (Blue)
local hiderTeam = Teams:FindFirstChild("Hider")
if not hiderTeam then
hiderTeam = Instance.new("Team")
hiderTeam.Name = "Hider"
hiderTeam.TeamColor = BrickColor.new("Bright blue")
hiderTeam.AutoAssignable = false
hiderTeam.Parent = Teams
end
end
-- Call once at script start
SetupTeams()
2. Role Assignment with Team Assignment
Modify your role assignment code in RunGame:
lua
-- Role selection and announcement
local players = Players:GetPlayers()
if #players < 1 then return end
local seekerIndex = math.random(1, #players)
local seeker = players[seekerIndex]
local roles = {}
for _, player in ipairs(players) do
local isSeeker = player == seeker
roles[player] = if isSeeker then "Seeker" else "Hider"
-- Assign team
player.Team = if isSeeker then Teams.Seeker else Teams.Hider
end
-- Announce to clients
local RoleAnnouncement = game.ReplicatedStorage:WaitForChild("RoleAnnouncement")
for player, role in pairs(roles) do
RoleAnnouncement:FireClient(player, role)
end
User
i want it so that there is not particles or highlight for hiders and hiders can see seeker highlighted and with particles, the seeker can be seen through structures to hiders, but on the seekers screen the seeker is not higlighted and clear the teams when the round is over.
Assistant
Here's the modified implementation for your specific requirements:
1. Server-Side Modifications (Main Script)
lua
-- Add new variables at top
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SeekersList = ReplicatedStorage:WaitForChild("SeekersList")
local RoundEnded = ReplicatedStorage:WaitForChild("RoundEnded")
-- Modify role assignment in RunGame()
local function RunGame(map)
-- [Previous code] Teleport players etc...
-- Role assignment
local players = Players:GetPlayers()
if #players < 1 then return end
local seekerIndex = math.random(1, #players)
local seeker = players[seekerIndex]
local roles = {}
local seekers = {}
for _, player in ipairs(players) do
local isSeeker = player == seeker
roles[player] = if isSeeker then "Seeker" else "Hider"
if isSeeker then
table.insert(seekers, player)
player.Team = Teams.Seeker
else
player.Team = Teams.Hider
end
end
-- Send role info to clients
local RoleAnnouncement = ReplicatedStorage:WaitForChild("RoleAnnouncement")
for player, role in pairs(roles) do
RoleAnnouncement:FireClient(player, role)
end
-- Send seekers list to all clients
SeekersList:FireAllClients(seekers)
-- [Rest of RunGame function]...
end
-- Add round end cleanup
local function EndRound()
-- Clear teams
for _, player in ipairs(Players:GetPlayers()) do
player.Team = nil
end
-- Notify clients
RoundEnded:FireAllClients()
end
The server uses RoleAnnouncement:FireClient() to send role data to each player.
Clients listen with RoleAnnouncement.OnClientEvent to receive their role.
Role Selection Logic:
Randomly picks a Seeker using math.random.
Stores roles in a table for potential future use (e.g., win conditions).
GUI Updates:
Creates a new TextLabel to display the role message. Adjust the position/size to match your UI.
Optional Enhancements:
Visual Feedback: Add particle effects or sounds when roles are assigned.
Team Colors: Use player.Team to visually distinguish Seekers/Hiders.
Error Handling: Check if RoleAnnouncement exists before firing.
This implementation ensures each player sees their role immediately when the game starts. The roles are randomly assigned each round during the map selection phase.
3. Enhanced Client-Side GUI (Update your LocalScript)
lua
local gui = script.Parent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Create role display
local roleLabel = Instance.new("TextLabel")
roleLabel.Name = "RoleDisplay"
roleLabel.Size = UDim2.new(0, 200, 0, 50)
roleLabel.Position = UDim2.new(0.5, -100, 0.1, 0)
roleLabel.BackgroundTransparency = 1
roleLabel.Font = Enum.Font.GothamBold
roleLabel.TextSize = 24
roleLabel.Parent = gui.Display
-- Create particle effects (preload in ReplicatedStorage)
local SeekerParticles = ReplicatedStorage:WaitForChild("SeekerParticles")
local HiderParticles = ReplicatedStorage:WaitForChild("HiderParticles")
-- Create sounds (preload in ReplicatedStorage)
local SeekerSound = ReplicatedStorage:WaitForChild("SeekerSound")
local HiderSound = ReplicatedStorage:WaitForChild("HiderSound")
local RoleAnnouncement = ReplicatedStorage:WaitForChild("RoleAnnouncement")
RoleAnnouncement.OnClientEvent:Connect(function(role)
-- Update text and color
roleLabel.Text = "You are a " .. role .. "!"
roleLabel.TextColor3 = if role == "Seeker" then Color3.new(1, 0, 0) else Color3.new(0, 0, 1)
-- Play sound
local sound = if role == "Seeker" then SeekerSound:Clone() else HiderSound:Clone()
sound.Parent = player.Character:WaitForChild("HumanoidRootPart")
sound:Play()
-- Add particles
local particle = if role == "Seeker" then SeekerParticles:Clone() else HiderParticles:Clone()
particle.Parent = player.Character:WaitForChild("HumanoidRootPart")
-- Optional: Add team-colored highlight to character
local highlight = Instance.new("Highlight")
highlight.FillColor = roleLabel.TextColor3
highlight.OutlineColor = roleLabel.TextColor3
highlight.Parent = player.Character
end)
4. Required Assets Setup
In ReplicatedStorage, add these assets:
Sound Objects:
Create two Sound objects named:
SeekerSound (load a "alert" sound)
HiderSound (load a "whisper" sound)
Configure properties like Volume, SoundId
Particle Effects:
Create two ParticleEmitter objects named:
SeekerParticles (configure red particles)
HiderParticles (configure blue particles)
Set properties like:
lua
-- Example configuration for SeekerParticles
SeekerParticles.Color = ColorSequence.new(Color3.new(1, 0, 0))
SeekerParticles.Lifetime = NumberRange.new(1, 2)
SeekerParticles.Speed = NumberRange.new(5, 10)
Key Features Added:
Team System:
Players are assigned to proper teams
Shows team colors in leaderboard/player lists
Visual Feedback:
Role text color matches team color
Custom particle effects spawn on player
Role-specific sounds play
Character Highlighting (Optional):
Added Highlight effect to make roles visually distinct
Team Colors:
Seeker: Red team/Bright red
Hider: Blue team/Bright blue
Notes:
Make sure to upload actual sound assets and configure ParticleEmitters properly
The Highlight effect requires the Highlight package (rbxassetid://11186872135)
Test particle effects in-game as they may need position/size adjustments
For team colors to show on characters, enable "Team Color" in Humanoid settings
This implementation creates a clear visual distinction between roles while maintaining team functionality for leaderboards and future gameplay mechanics.
lua
local gui = script.Parent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Preload assets
local SeekerParticles = ReplicatedStorage:WaitForChild("SeekerParticles")
local RoleAnnouncement = ReplicatedStorage:WaitForChild("RoleAnnouncement")
local SeekersList = ReplicatedStorage:WaitForChild("SeekersList")
local RoundEnded = ReplicatedStorage:WaitForChild("RoundEnded")
-- Role display setup
local roleLabel = gui.Display.RoleDisplay -- Use your existing GUI element
-- Track added effects
local activeEffects = {}
local function AddSeekerEffects(character)
-- Only add if not already exists
if not character:FindFirstChild("SeekerHighlight") then
-- Create Highlight
local highlight = Instance.new("Highlight")
highlight.Name = "SeekerHighlight"
highlight.FillColor = Color3.new(1, 0, 0)
highlight.OutlineColor = Color3.new(1, 0, 0)
highlight.Parent = character
-- Create Particle Effect
local particles = SeekerParticles:Clone()
particles.Name = "SeekerParticles"
particles.Parent = character:FindFirstChild("HumanoidRootPart")
-- Track effects
table.insert(activeEffects, highlight)
table.insert(activeEffects, particles)
end
end
-- Role announcement handler
RoleAnnouncement.OnClientEvent:Connect(function(role)
roleLabel.Text = "You are a " .. role .. "!"
roleLabel.TextColor3 = role == "Seeker" and Color3.new(1, 0, 0) or Color3.new(0, 0, 1)
end)
-- Seeker list handler
SeekersList.OnClientEvent:Connect(function(seekers)
if roleLabel.Text == "You are a Hider!" then
-- Clear previous effects
for _, effect in ipairs(activeEffects) do
if effect.Parent then effect:Destroy() end
end
activeEffects = {}
-- Add new effects
for _, seeker in ipairs(seekers) do
if seeker ~= player then -- Don't add to self if seeker
local success, character = pcall(function()
return seeker.Character or seeker.CharacterAdded:Wait()
end)
if success and character then
AddSeekerEffects(character)
-- Track future characters
seeker.CharacterAdded:Connect(function(newChar)
AddSeekerEffects(newChar)
end)
end
end
end
end
end)
-- Round end cleanup
RoundEnded.OnClientEvent:Connect(function()
for _, effect in ipairs(activeEffects) do
if effect.Parent then effect:Destroy() end
end
activeEffects = {}
end)
3. Required Asset Setup
In ReplicatedStorage:
Create a ParticleEmitter named SeekerParticles with:
Color: Bright red
Lifetime: 1-2 seconds
Transparency: 0.5
Size: 0.2, 0.5
Texture: Choose a glowing particle texture
EmissionDirection: Top
Create a RemoteEvent named SeekersList
Create a RemoteEvent named RoundEnded
Key Features:
Hider-Centric Effects:
Only hiders see seeker highlights/particles
Effects automatically update when seekers respawn
Effects clear when round ends
Wall Visibility:
Highlight effect naturally shows through walls
Particles provide additional visual cue
Team Management:
Teams are properly assigned and cleared
No leftover team assignments between rounds
Performance:
Effects are properly tracked and cleaned up
No duplicate effects created
Testing Tips:
Verify particles are visible through walls
Check that seekers don't see their own effects
Confirm teams reset after round ends
Test with multiple seekers (if you modify to allow multiple)
This implementation creates clear visual distinction while maintaining performance and proper cleanup between rounds.