Hey Everyone,
So I’m making a minigame game, and I’m stuck. Firstly, this issue only occures with 2+ players, when you play solo it works fine. What happens is, when the minigame ends, it shows the winners, and then it starts the next minigame, but it doesn’t teleport the players, nor does the top text change, but if the loop gives them a tool, like the sword fight, they get it.
I have no idea why this is happening, I get no errors at all.
Here is my script:
-- Tables
local Contestants = {}
-- Services
local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ServerStorage = game:GetService('ServerStorage')
-- Other Variables
local Values = ReplicatedStorage:WaitForChild('Values')
local Events = ReplicatedStorage:WaitForChild('Events')
local TopText = Values:WaitForChild('TopText')
local module = require(game.ReplicatedStorage.Modules:WaitForChild('MusicPlayer'))
-- Settings
local RoundDuration = 30 -- Duration of the round (in seconds)
-- Functions
local function RemovePlayerFromTable(Player)
if table.find(Contestants,Player) and Player then
local ReturnValue = table.find(Contestants,Player)
table.remove(Contestants,ReturnValue)
end
end
local function AddPlayersToTable()
for _, Player in pairs(game.Players:GetPlayers()) do
if Player then
table.insert(Contestants,Player)
end
end
end
local function MakeChatInvisible(Player)
game.ReplicatedStorage.Events.ControlChat:FireClient(Player,false)
end
-- Connections
Events.RemovePlayerFromTable.OnServerEvent:Connect(RemovePlayerFromTable)
game.Players.PlayerAdded:Connect(MakeChatInvisible)
local StayAliveMinigames = {"SpinnerMap", "Sword Fighting", "WarMap"}
-- Main Game Loop
while true do
repeat wait() until game.ReplicatedStorage:WaitForChild("Events"):FindFirstChild("RefreshVoting")
game.ReplicatedStorage:WaitForChild("Events").RefreshVoting:Fire()
print("Fired")
wait()
local SongToPlay = game.Workspace.Lobby.LobbyMusic:GetChildren()[math.random(1,#game.Workspace.Lobby.LobbyMusic:GetChildren())]
SongToPlay:Play()
SongToPlay.Looped = true
for i = RoundDuration,0,-1 do
TopText.Value = 'The next minigame will be chosen in '..i..' seconds'
wait(1)
end
local Maps = game.ServerStorage:WaitForChild("Maps")
local ChosenMinigame = game.ServerStorage:WaitForChild("Assets").Map.Value
if ChosenMinigame == nil or ChosenMinigame == "" or ChosenMinigame == " " then ChosenMinigame = Maps:GetChildren()[math.random(1,#Maps:GetChildren())] else local ChosenMinigame = Maps[game.ServerStorage:WaitForChild("Assets").Map.Value] end
ChosenMinigame = Maps:FindFirstChild(game.ServerStorage.Assets.Map.Value)
if ChosenMinigame == nil or ChosenMinigame == false then
ChosenMinigame = Maps:GetChildren()[math.random(1,#Maps:GetChildren())]
end
local Map = ChosenMinigame:Clone()
Map.Parent = game:GetService("Workspace")
local Clone = game.ServerStorage:WaitForChild("Assets").ChosenMinigame
Clone.Frame.ImageLabel.Image = Map.MinigameInfo.ImageToDisplay.Value
Clone.Frame.ImageLabel.Title.Text = Map.Name
Clone.Frame.Description.Text = Map.MinigameInfo.Description.Value
wait()
for i, Player in pairs(game.Players:GetPlayers()) do
spawn(function()
Clone:Clone().Parent = Player.PlayerGui
end)
end
wait(.3)
game.ReplicatedStorage.Events.MakeNewTween:FireAllClients('TweenMinigameInfoIn')
TopText.Value = 'Minigame Chosen'
wait(2.5)
for i = 10,0,-1 do
TopText.Value = 'Teleporting Players in '..i..' seconds'
wait(1)
end
game.ReplicatedStorage.Events.StopSong:Fire()
for i, Player in pairs(game.Players:GetPlayers()) do
spawn(function()
if Player and Player.Character ~= nil and Player.Character.Humanoid.Health > 0 then
table.insert(Contestants,Player)
Player.Status.Value = "Playing"
if Player.Character.Humanoid.Sit == true then
Player.Character.Humanoid.Sit = false
wait(.3)
end
Player.Character.HumanoidRootPart.CFrame = Map.Spawns:GetChildren()[i].CFrame + Vector3.new(0,2,0)
end
end)
end
wait(1)
game.ReplicatedStorage:WaitForChild('Events').MakeNewTween:FireAllClients('TweenMinigameInfoOut')
SongToPlay.Looped = false
SongToPlay:Stop()
for i, Player in pairs(game.Players:GetPlayers()) do
spawn(function()
Player:WaitForChild("PlayerGui")
--Player.PlayerGui.ChosenMinigame:Destroy()
end)
if ChosenMinigame.Name == "Speedrun" then
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
local char = v.Character or v.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
--script.Parent:WaitForChild("NinjaAnimation").Disabled = false
hum.WalkSpeed = 70
hum.JumpPower = 100
end
end
if ChosenMinigame.Name == "SpinnerMap" then
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
local char = v.Character or v.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
hum.WalkSpeed = 0
end
end
if ChosenMinigame.Name == "Sword Fighting" then
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
local backpack = v:WaitForChild("Backpack")
local sword = ReplicatedStorage:WaitForChild("Tools").Sword:Clone()
sword.Parent = backpack
end
end
if ChosenMinigame.Name == "WarMap" then
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
local backpack = v:WaitForChild("Backpack")
local gun = ServerStorage:WaitForChild("Assets")
gun.Parent = backpack
end
end
for i = ChosenMinigame:WaitForChild('MinigameInfo').Time.Value, 0 ,-1 do
TopText.Value = 'Round in progress ('..i..')'
local winsp = 0
local plrs = 0
local pplrs = 0
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
local char = v.Character or v.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
if v.Status.Value == "Playing" then pplrs = pplrs + 1 end
if v.Status.Value == "Won" then winsp = winsp + 1 else end
if hum.Health <= 0 then
v.Status.Value = "Lost"
plrs = plrs + 1
end
end
if plrs == #game:GetService("Players"):GetPlayers() then
TopText.Value = "Everyone died!"
break
end
if winsp == #game:GetService("Players"):GetPlayers() then
TopText.Value = "Everyone won!"
break
end
if pplrs == 0 then
break
end
if pplrs == 1 and ChosenMinigame.Name == "Sword Fighting" or ChosenMinigame.Name == "WarMap" then
print("yes")
Map.Barriers.EndBarrier.Script.Disabled = false
end
wait(1)
end
wait(1)
if ChosenMinigame.Name == "SpinnerMap" then
wait(1.75)
Map.Barriers.EndBarrier.Script.Disabled = false
end
TopText.Value = "Game Over!"
wait(1.75)
Map:Destroy()
wait()
for i,v in pairs(game.Players:GetPlayers()) do
local char = v.Character or v.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
hrp.CFrame = game.Workspace.Lobby.LobbySpawns.SpawnLocation.CFrame + Vector3.new(0,3,0)
hrp.Parent.Humanoid.WalkSpeed = 16
hrp.Parent.Humanoid.JumpPower = 50
end
local winners = {}
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
if v.Status.Value == "Won" then
table.insert(winners, v.Name)
end
v.Status.Value = "Nil"
end
if winners[1] ~= nil then
TopText.Value = "Winners: "..table.concat(winners,", ")
end
wait(5)
end
game.ServerStorage:WaitForChild("Assets").Map.Value = ""
for i,v in pairs(game.Workspace.Lobby.LobbyMusic:GetChildren()) do
game:GetService("TweenService"):Create(v, TweenInfo.new(5), {Volume=0.8}):Play()
end
--script.Parent:WaitForChild("NinjaAnimation").Disabled = false
end
I’d really appreciate some help!