I am trying to make a script where there is a 30 second timer and you need to get into a room and if you are not in that room you die here is my current script
local player = game.Players.LocalPlayer
local TimerEvent = game.ReplicatedStorage.TimerEvent
local ScreenGui = player.PlayerGui.ScreenGui
local randomCharacter
local randomCharacterName
local function getRandomCharacter()
local players = game.Players:GetPlayers()
repeat
local number = math.random(1,#players)
local randomPlayer = players[number]
randomCharacter = randomPlayer.Character
until randomCharacter
randomCharacterName = randomCharacter.Name
randomCharacter.Archivable = true
end
local function killPlayer()
– Modify this function to handle the player’s death however you want
player.Character:BreakJoints()
end
local stopTimer = false
TimerEvent.OnClientEvent:Connect(function(timer, isInRoom)
ScreenGui.TimerFrame.TextLabel.Text = timer
ScreenGui.TimerFrame.TextLabel.Visible = true
wait(1)
repeat
timer = timer - 1
ScreenGui.TimerFrame.TextLabel.Text = timer
wait(1)
until timer <= 0 or stopTimer
ScreenGui.TimerFrame.TextLabel.Visible = false
if not isInRoom then
killPlayer()
end
stopTimer = false
end)
local function checkRoom()
local isInRoom = false
local offset = Vector3.new(, 0, 0)
local roomCenter = roomPart.Position + offset
local roomExtents = roomSize / 2
local playerPosition = character.HumanoidRootPart.Position
-- Check if the player's position is within the room's boundaries
if math.abs(playerPosition.X - roomCenter.X) <= roomExtents.X and
math.abs(playerPosition.Y - roomCenter.Y) <= roomExtents.Y and
math.abs(playerPosition.Z - roomCenter.Z) <= roomExtents.Z then
isInRoom = true
end
end
– Replace the following lines with your actual implementation
local character = player.Character
if character then
– Replace “Bedrooms” with the name or identifier of the designated room
if character:FindFirstChild(“Bedrooms”) then
isInRoom = true
end
end
TimerEvent:FireServer(30, isInRoom)
end
please review it and tell me what is wrong so I can improve in the future