I made a game where the player wins when he touches a part at the end of a random map where he got teleported.
Basically I want that when the player wins, confetti are enabled for like 10 seconds.
Note that I put confetti in a transparent part above the spawn points, where the players gets teleported when he wins.
This is the script (‘Main’) that handles the win system. My attempts didn’t work, but I’m kinda noob and I don’t have much experience.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local vals = ReplicatedStorage.vals
local Sound1 = script.Parent.TimeSound
local Sound2 = script.Parent.Sound2
local s = script.Stat
local blocco = script.Parent.BloccoPartenza
local conf = script.Parent.ConfettiGiver.Confetti
--//Controls
local timeRemaining = 0
--//Tables
local timeValues = {
[3] = "Ready",
[2] = "Steady",
[1] = "Set",
[0] = "Go!",
}
--//Loops
while true do
--//Intermission
timeRemaining = 30
repeat
timeRemaining -= 1
s.Value = "Intermission... ".. timeRemaining
task.wait(1)
until timeRemaining == 0
s.Value = "Game starting!"
task.wait(2)
blocco.CanCollide = true
local mapselect = ReplicatedStorage.Games:GetChildren()
local choose = Random.new():NextInteger(1, #mapselect)
local curnum = 0
for i = 1, #mapselect do
curnum += 1
if curnum == choose then
mapselect[i]:Clone().Parent = workspace
curmap = mapselect[i].Name
s.Value = "We'll be playing "..mapselect[i].Name
end
end
task.wait(3)
--//Start game
local plrs = Players:GetPlayers()
for i, player in ipairs(Players:GetPlayers()) do
pcall(player.LoadCharacter, player)
task.defer(function()
local randomNumber = Random.new():NextInteger(1, 32)
player.Character.Head.CFrame = CFrame.new(workspace.Teleports["Part".. randomNumber].Position)
player.Character.Parent = workspace.Ingame
end)
end
timeRemaining = 4
repeat
timeRemaining -= 1
s.Value = timeValues[timeRemaining]
if s.Value == "Go!" then
blocco.CanCollide = false
end
if s.Value == "Ready" then
Sound2:Play()
end
task.wait(1)
until timeRemaining == 0
timeRemaining = 120
repeat
timeRemaining -= 1
s.Value = timeRemaining.." seconds left"
if timeRemaining == 10 then
Sound1:Play()
end
task.wait(1)
until timeRemaining == 0 or vals.Winner.Value ~= "" or #workspace.Ingame:GetChildren() == 0
--//End game
if vals.Winner.Value ~= "" then
s.Value = vals.Winner.Value.. " has won!"
Players[vals.Winner.Value].leaderstats.Wins.Value = game.Players[vals.Winner.Value].leaderstats.Wins.Value +1
vals.Winner.Value = ""
if #workspace.Ingame:GetChildren() == 0 then
s.Value = "No one has won!"
end
else
s.Value = "No one has won!"
end
if s.Value == vals.Winner.Value.. " has won!" then
conf.Enabled = true
task.delay(10,function()
conf.Enabled = false
end)
end
if vals.Winner.Value =="" then
Sound1:Stop()
end
task.wait(3)
local ingame = workspace.Ingame:GetChildren()
for i = 1, #ingame do
local player = Players:GetPlayerFromCharacter(ingame[i])
pcall(player.LoadCharacter, player)
end
workspace[curmap]:Destroy()
end
Thank you for putting the time into reading this and helping out!