Hello devs,
i have this round script, sorry ikk its long, and i have this event that fires perfectly when a player wins. This all works fine, but i want it so that when the win event is called, the round will end. I’ve tried putting the timeLeft to 0, but that changes the music to the lobby music, but it doesnt teleport the player or destroy the map, and if you see my print statement print("got here 1") and print("got here 2") it only prints got me here 1. Heres my script.
local roundTime = 500
local intermissionTime = 10
local timeLeft
local status
local roundHandler = game:GetService("ReplicatedStorage"):WaitForChild("RoundHandler")
local transitionEndedEvent = game.ReplicatedStorage.TransitionEnded
local maps = {
"Robloxian House",
"Castle"
}
local winner
local mapFolder = workspace.CurrentMap
local lobbyMusic = game.ServerStorage.Music.Lobby:Clone()
local gameMusic = game.ServerStorage.Music.Game:Clone()
lobbyMusic.Parent = workspace
local clientWonEvent = game.ReplicatedStorage.WonEvent
local wonEvent = game.ServerStorage.WonEvent
local function protectorCharLoad(plr)
local protectorValue = plr.ProtectorCharacter
local oldCharacter = plr.Character
local newCharacter = game:GetService("ServerStorage"):WaitForChild("Characters").Protectors:FindFirstChild(protectorValue.Value):Clone()
newCharacter.HumanoidRootPart.Anchored = false
newCharacter:SetPrimaryPartCFrame(oldCharacter.PrimaryPart.CFrame)
plr.Character = newCharacter
newCharacter.Parent = workspace.InGameChars.Protector
return plr
end
local function destroyerCharLoad(plr)
local destroyerValue = plr.DestroyerCharacter
local oldCharacter = plr.Character
local newCharacter = game:GetService("ServerStorage"):WaitForChild("Characters").Destroyers:FindFirstChild(destroyerValue.Value):Clone()
newCharacter.HumanoidRootPart.Anchored = false
newCharacter:SetPrimaryPartCFrame(oldCharacter.PrimaryPart.CFrame)
plr.Character = newCharacter
newCharacter.Parent = workspace.InGameChars.Protector
return plr
end
timeLeft = intermissionTime
status = "Intermission"
task.wait(1)
wonEvent.Event:Connect(function()
timeLeft = 1
status = "Game"
winner = "Destroyers"
end)
while true do
if timeLeft ~= 0 then
timeLeft -= 1
else
if timeLeft == 0 then
if status == "Intermission" then
winner = nil
timeLeft = roundTime
status = "Game"
gameMusic:Play()
gameMusic.Parent = workspace
if lobbyMusic.IsPlaying == true then
lobbyMusic:Stop()
lobbyMusic.Parent = game.ServerStorage.Music
end
else
timeLeft = intermissionTime
status = "Intermission"
lobbyMusic:Play()
lobbyMusic.Parent = workspace
if winner == nil then
winner = "Protectors"
else
winner = "Destroyers"
end
clientWonEvent:FireAllClients(winner)
if gameMusic.IsPlaying == true then
gameMusic:Stop()
gameMusic.Parent = game.ServerStorage.Music
end
print("got here 1")
end
end
end
if status == "Game" and timeLeft == roundTime then
local ranNum = math.random(1, #maps)
local map = game:GetService("ServerStorage"):WaitForChild("Maps"):FindFirstChild(maps[ranNum]):Clone()
map.Parent = workspace.CurrentMap
local roundSpawnPart = map:WaitForChild("SpawnPart")
task.wait(1)
for i, v in game.Players:GetChildren() do
v.Character:MoveTo(roundSpawnPart.Position)
transitionEndedEvent.OnServerEvent:Wait()
if v.GameTeam.Value == "Destroyer" then
destroyerCharLoad(v)
elseif v.GameTeam.Value == "Protector" then
protectorCharLoad(v)
end
end
end
if status == "Intermission" and timeLeft == intermissionTime then
for i, v in game.Players:GetChildren() do
transitionEndedEvent.OnServerEvent:Wait()
v.Character.Humanoid.Health = 0
end
for i, v in workspace.CurrentMap:GetChildren() do
v:Destroy()
end
print("got here 2")
end
roundHandler:FireAllClients(timeLeft, status, roundTime, intermissionTime)
task.wait(1)
end
Im sorry its so long, its one of my main scripts. Id love if you had a look at it, as i’m stumped. Also any optimisation suggestions are welcome, but this is mainly about ending the round.