I am making a game script but when all players die it does work once but then after again it doesn’t do anything when everyone dies anyone know why?
Handler:
local Players = game:GetService("Players")
local RoundModule = require(script.Parent.Parent.RoundModule)
Players.PlayerAdded:Connect(function(player)
local playing = Instance.new("BoolValue")
playing.Parent = player
playing.Name = "Playing"
playing.Value = false
local baldi = Instance.new("BoolValue")
baldi.Parent = player
baldi.Name = "Baldi"
baldi.Value = false
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
humanoid.Died:Connect(function()
if workspace.Values.Game.Value == true and player.Playing.Value == true then
player.Playing.Value = false
workspace.Values.Players.Value = workspace.Values.Players.Value - 1
end
end)
end)
Players.PlayerRemoving:Connect(function(player)
if player.Playing.Value == true and workspace.Values.Game.Value == true then
workspace.Values.Players.Value = workspace.Values.Players.Value - 1
end
end)
debounce = false
while true do
repeat wait() until workspace.Values.Players.Value == 0
if debounce == false and workspace.Values.Game.Value == true then
debounce = true
local descendants = game.Workspace:GetDescendants()
for i,v in pairs(descendants) do
if v:IsA("Sound") then
v.Playing = false
end
end
RoundModule.end_game()
end
end
Module:
local module = {}
function module.end_game()
print("The game has ended.")
workspace.Values.Game.Value = false
print(workspace.Values.Players.Value)
workspace.Music["Ahh, fresh meat!"]:Play()
script.Parent.GameScript:Destroy()
end
return module
Autofix:
wait(5)
local GameScript = game.ServerScriptService.GameScript:Clone()
GameScript.Parent = game.Lighting
while true do
repeat wait() until not game.ServerScriptService:FindFirstChild("GameScript")
GameScript:Clone().Parent = game.ServerScriptService
wait(5)
end
Anyone know why this happens? And the Handler is in the GameScript btw.