Hi, im making a game were there is one killer and the rest is survivors. When the Intermission goes down to 0 i wanted all the survivors to teleport to the map but the killer will teleport to his waiting room. And when the rond ends everyone teleport back to the lobby.
The problem is that when the intermission turns 0 nothing happends but the round timer starts to go down.
I have spent some days now searching online and watching tutorials but i cant find a solution.
I started to learn scripting about a month ago so im pretty new to this. I hope someone can help me fix this so i can continue making my game. Thanks.
Here is my script
--Killer/Survivor Picker
local killer = nil
local survivors = {}
function PickPlayers()
survivors = {}
local plrs = game.Players:GetChildren()
local KillerID = math.random(1, #plrs)
for i, v in pairs(plrs) do
if i == KillerID then
killer = v.Name
break
end
end
for i, v in pairs(plrs) do
if i == KillerID then
else
table.insert(survivors, v.Name)
end
end
print("Killer: ".. killer)
for i, v in pairs(survivors) do
print("Survivor: ".. v)
end
end
while wait(5) do
PickPlayers()
break
end
--Intermission, Roundtimer and Teleport
local roundLength = 100
local intermissionLength = 10
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local LobbySpawn = game.Workspace.Lobby.Spawns.LobbySpawn
local GameAreaSpawn = game.Workspace.Hallway.Spawns.MapSpawn
local KillerAreaSpawn = game.Workspace.WaitingRoom.KillerWaitingSpawn
--Teleport
InRound.Changed:Connect(function()
if InRound.Value == true then
for i, v in pairs(survivors) do
local char = v.Character
char.HumanoidRootPart.CFrame = GameAreaSpawn.CFrame
end
else
for i, v in pairs(killer) do
local char = v.Character
char.HumanoidRootPart.CFrame = KillerAreaSpawn.CFrame
end
end
end)
InRound.Changed:Connect(function()
if InRound.Value == false then
for i, v in pairs(game.Players:GetChildren()) do
local char = v.Character
char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
end
end
end)
--Intermission
local function roundTimer()
while wait() do
for i = intermissionLength, 0, -1 do
InRound.Value = false
wait(1)
Status.Value = "Intermission In ".. i .. ""
end
for i = roundLength, 0, -1 do
InRound.Value = true
wait(1)
Status.Value = "Game Ends In ".. i ..""
end
end
end
spawn(roundTimer)
If you know tips or ways to fix/make the script better, please let me know.
When the roundlength timer starts thats when the players gets tpâed so if i change it the players gets tpâed the the lobby when the round starts. So it turns true when the round starts and then they get tpâed.
So i edited the script and here is the working version:
wait(3) -- Added a wait time
--Killer/Survivor Picker
local killer = nil
local survivors = {}
function PickPlayers()
survivors = {}
local plrs = game.Players:GetChildren()
local KillerID = math.random(1, #plrs)
for i, v in pairs(plrs) do
if i == KillerID then
killer = v.Name
break
end
end
for i, v in pairs(plrs) do
if i == KillerID then
else
table.insert(survivors, v.Name)
end
end
print("Killer: ".. killer)
for i, v in pairs(survivors) do
print("Survivor: ".. v)
end
end
while wait(5) do
PickPlayers()
print("Picked")
break
end
--Intermission, Roundtimer and Teleport
local roundLength = 100
local intermissionLength = 10
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local LobbySpawn = game.Workspace.Lobby.Spawns.LobbySpawn
local GameAreaSpawn = game.Workspace.Hallway.Spawns.MapSpawn
local KillerAreaSpawn = game.Workspace.WaitingRoom.KillerWaitingSpawn
--Teleport
InRound.Changed:Connect(function()
if InRound.Value == true then
for i, v in pairs(survivors) do
game.Workspace[v].HumanoidRootPart.CFrame = GameAreaSpawn.CFrame -- Finding the player in the workspace
end
print(killer) -- Removed the else
game.Workspace[killer].HumanoidRootPart.CFrame = KillerAreaSpawn.CFrame -- Finding the player in the workspace
end
end)
InRound.Changed:Connect(function()
if InRound.Value == false then
for i, v in pairs(game.Players:GetChildren()) do
game.Workspace[v].HumanoidRootPart.CFrame = LobbySpawn.CFrame
end
end
end)
--Intermission
local function roundTimer()
while wait() do
for i = intermissionLength, 0, -1 do
InRound.Value = false
wait(1)
Status.Value = "Intermission In ".. i .. ""
end
for i = roundLength, 0, -1 do
InRound.Value = true
print("InRound = true")
wait(1)
Status.Value = "Game Ends In ".. i ..""
end
end
end
spawn(roundTimer)