I am making a mini games style game where there is a combination of team games and free for all games. I am not an expert at scripting but here is what I have been able to come up with:
local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage:WaitForChild('StatusValue')
local mapstorage = game.Workspace:WaitForChild('Maps')
local tele = replicatedstorage:WaitForChild("BlueVictory")
local tele1 = replicatedstorage:WaitForChild("RedVictory")
while true do
game.Workspace.Music.RoundEnded:Stop()
while game.Players.NumPlayers < 2 do
status.Value = "2 Or More Players Needed. Invite Your Friends Or Play The Solo Levels!"
repeat wait(2) until game.Players.NumPlayers >= 2
end
game.Workspace.Music.WFCfast:Play()
for i = 20,0,-1 do -- you can adjust the #90 to how long you want to intermission to last.
status.Value = "Intermission "..i
wait(1)
end
_G.gameplayers = {}
for i, v in pairs(game.Players:GetPlayers()) do
if v then
table.insert(_G.gameplayers, v.Name)
end
end
local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren()
chosenmap = mapsinserverstorage[math.random(1, #mapsinserverstorage)]
chosenmap:Clone().Parent = mapstorage
wait(1)
status.Value = "Map chosen: "..chosenmap.Name
wait(3)
status.Value = "Get Ready!"
game.Workspace.Music.WFCfast:Stop()
game.Workspace.Music.getready:Play()
wait(5)
game.Workspace.Music.RoundStarting:Play()
local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
for _, player in pairs (game.Players:GetPlayers()) do
if player and #spawns > 0 then
local Torso = player.Character:WaitForChild('UpperTorso')
local allspawns = math.random(1, #spawns)
local randomspawn = spawns[allspawns]
if randomspawn and Torso then
table.remove(spawns, allspawns)
Torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
function fadeTo(a, b, c)
for transparency = a, b, c do
--go from a to b, counting by c
for _, part in pairs(player.Character:GetChildren()) do
--for each of the objects in the character,
if part:IsA("BasePart") then
--check if it's a part, and if so
part.Transparency = transparency
--set its transparency
end
end
wait(0.1)
end
end
--local primary = game.ReplicatedStorage.TeslaBlaster -- CHANGE THIS TO WHATEVER ITEM YOU WANT TO GIVE THEM WHEN THEY ARE TELEPORTED. MAKE SURE IT IS IN REPLICATED STORAGE.
--local newprimary = primary:Clone()
--newprimary.Parent = player.Backpack
end
end
end
game.Workspace.Music.RoundStarting:Stop()
status.Value = "START"
mapname = chosenmap.Name
chosenmapstart = game.Workspace.GameScripts.EscapeTheFacility
chosenmapstart.Disabled = false
wait(4)
for i = 120,0,-1 do -- You can adjust the #120 to how long you want the round to last.
status.Value = i.." Seconds Remaining!"
if i == 0 then
status.Value = "Out Of Time!"
chosenmapstart.Disabled = true
game.Workspace.Music.RoundEnded:Play()
wait(10)
break
else
function bluewin()
status.Value = "The Thieves have won the game!"
game.Workspace.Music.RoundEnded:Play()
end
end
function redwin()
status.Value = "The Bandits have won the game!"
game.Workspace.Music.RoundEnded:Play()
end
end
end
mapstorage:ClearAllChildren()
wait(1)
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
chosenmap.BlueParkour.Model.Exit.ClickDetector.MouseClick:Connect(bluewin)
chosenmap.RedParkour.Model.Exit.ClickDetector.MouseClick:Connect(redwin)
That was the main script
--Master script for EscapeTheFacility minigame
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local tele = ReplicatedStorage:WaitForChild("BlueVictory")
local tele1 = ReplicatedStorage:WaitForChild("RedVictory")
function bluewin()
game.Workspace.Maps:WaitForChild("Escape The Facility")
tele:FireServer()
end
function redwin()
game.Workspace.Maps:WaitForChild("Escape The Facility")
tele1:FireServer()
end
game.Workspace.Maps["Escape The Facility"].RedParkour.Model.Exit.ClickDetector.MouseClick:Connect(redwin)
game.Workspace.Maps["Escape The Facility"].BlueParkour.Model.Exit.ClickDetector.MouseClick:Connect(bluewin)
That was the master script, activated when the Escape The Facility minigame was chosen. This would fire the Victory event, telling the server that a team has won. So far, this is the only minigame i have made so far so please keep that in mind if you're making a solution.
The problem is that when the players are teleported, the game runs in an endless loop of saying "Time's Up!" straight after it says "Start". What am I doing wrong and how do i fix it all to make the whole thing work?
