so i made a round system and after the next round everything just breaks, how do i fix this?
theres no errors or anything it just breaks
local replicatedstorage = game:GetService("ReplicatedStorage")
local game_folder = replicatedstorage.game
local remotes_folder = game_folder.remotes
local values_folder = game_folder.values
local soundservice = game:GetService("SoundService")
local soundgroup = soundservice.soundsgroup
local plrs = game:GetService("Players")
local tweenService = game:GetService("TweenService")
local tInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tInfo2 = TweenInfo.new(0.4, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local Lobby_Music_Tween_1 = tweenService:Create(soundgroup.lobby_theme, tInfo, {Volume = 1.3})
local Lobby_Music_Tween_0 = tweenService:Create(soundgroup.lobby_theme, tInfo, {Volume = 0})
playersinRound = {}
minimum_player_to_play = 2
required_player = 1
local function removePlayerfromRound(player)
local index = table.find(playersinRound, player)
if index then
print(player, "has left the round")
table.remove(playersinRound, index)
end
end
game.Players.PlayerRemoving:Connect(removePlayerfromRound)
plrs.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
if player:FindFirstChild("values_folder") == nil then
local new_folder = Instance.new("Folder", player)
local isSurvivor_Value = Instance.new("BoolValue", new_folder)
local isKiller_Value = Instance.new("BoolValue", new_folder)
isSurvivor_Value.Name = "isSurvivor"
isKiller_Value.Name = "isKiller"
new_folder.Name = "values_folder"
elseif player:FindFirstChild("values_folder") then
return
end
end)
end)
plrs.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local player_values = player:WaitForChild("values_folder")
player_values.isKiller.Changed:Connect(function()
if player_values.isKiller.Value == true then
local cloned_tag = game:GetService("ReplicatedStorage").killer_tag:Clone()
cloned_tag.Parent = player.Character:WaitForChild("Head")
elseif player_values.isKiller.Value == false then
player.Character:WaitForChild("Head"):FindFirstChild("killer_tag"):Destroy()
end
player_values.isSurvivor.Changed:Connect(function()
if player_values.isSurvivor.Value == true then
local cloned_tag = game:GetService("ReplicatedStorage").survivor_tag:Clone()
local character = player.Character
cloned_tag.Parent = character:WaitForChild("Head")
elseif player_values.isSurvivor.Value == false then
local character = player.Character
character:WaitForChild("Head"):FindFirstChild("survivor_tag"):Destroy()
end
end)
end)
end)
end)
local function system(player)
wait(3)
print("start again")
values_folder.time.Value = 120
values_folder.teleport.Value = false
values_folder.blackout.Value = false
values_folder.inRound.Value = false
values_folder.can_show.Value = true
values_folder.killer_user.Value = "none"
Lobby_Music_Tween_1:Play()
soundgroup.tick:Play()
soundgroup.lobby_theme:Play()
local chosen = plrs:GetChildren()[math.random(1, #plrs:GetChildren())]
local player = game:GetService("Players"):GetPlayers()[1]
player:WaitForChild("values_folder").isSurvivor.Value = false
chosen:WaitForChild("values_folder").isKiller.Value = false
playersinRound = {}
local connections = {}
--repeat wait() until game.Players.NumPlayers >= required_player
if game.Players.NumPlayers >= required_player then
repeat wait(1) values_folder.time.Value -= 1; remotes_folder.change_text:FireAllClients(); remotes_folder.change_text:FireAllClients(); until
values_folder.time.Value <= 0
Lobby_Music_Tween_0:Play()
if values_folder.time.Value == 0 then
wait(1)
values_folder.round_start.Value = true
soundgroup.tick:Stop()
print("round starting")
soundgroup.clock_chime:Play()
end
wait(8)
print("starting")
values_folder.killer_user.Value = chosen.Name
print("killer is "..values_folder.killer_user.Value)
chosen:WaitForChild("values_folder").isKiller.Value = true
chosen:WaitForChild("values_folder").isSurvivor.Value = false
if player:WaitForChild("values_folder").isSurvivor.Value == false and player.values_folder.isKiller.Value == false then
player:WaitForChild("values_folder").isSurvivor.Value = true
print(player.Name.." is survivor")
end
wait(3)
values_folder.time.Value = 120
--values_folder.teleport.Value = true
for i, player in pairs(game.Players:GetPlayers()) do
if player.Character and player.Character:FindFirstChild("Humanoid") then
local rootpart = player.Character:WaitForChild("HumanoidRootPart")
rootpart.CFrame = workspace.game.spawn.CFrame
table.insert(playersinRound, player)
connections[player.Name] = player.Character.Humanoid.Died:Connect(function()
if player:WaitForChild("values_folder").isSurvivor.Value == true then
removePlayerfromRound(player)
end
end)
if player:WaitForChild("values_folder").isKiller.Value == true then
player.Character:WaitForChild("HumanoidRootPart").CFrame = workspace.game.killer_spawn.CFrame
end
end
end
wait(3.2)
game_folder.values.inRound.Value = true
repeat wait(1) values_folder.time.Value -= 1; remotes_folder.change_text:FireAllClients(); until
values_folder.time.Value <= 0
for i, connection in pairs(connections) do
connection:Disconnect()
end
wait(4)
end
end
spawn(system)