Why dont confetti effect work?

  1. Basically I want that when someone wins in my game confetti are enabled for like 10 sec. To do this, I put a transparent part above the spawn points (where the players get teleported after the round ends; a round ends when someone wins by touching a part) that contains 7 particle emitters(confetti). Note that by default I set in the confetti properties enabled as false.
    This is the script (called ‘Main’):
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


--//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
		for _, conf in workspace.ConfettiGiver:GetChildren() do
			conf.Enabled = true
			task.delay(10,function()
				conf.Enabled = false
			end)
		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

The part in the Main script where I try to enable confetti whenever someone wins:

if s.Value == vals.Winner.Value.. " has won!" then
	for _, conf in workspace.ConfettiGiver:GetChildren() do
		conf.Enabled = true
		task.delay(10,function()
			conf.Enabled = false
		end)
	end
end

Screen

Despite the script seemed okay to me, it doesn’t work and I cant figure out why (I dont see any error in the output)

i have no experience yet and i am a new roblox studio user so please be patient. Also thanks for your attention, any help is appreciated

This only runs once, probably when the game starts but I can’t tell without seeing the whole script.

To run it every time the value is set, try

s.Changed:Connect(function()
if s.Value == vals.Winner.Value.. " has won!" then
	for _, conf in workspace.ConfettiGiver:GetChildren() do
		conf.Enabled = true
		task.delay(10,function()
			conf.Enabled = false
		end)
	end
end
end)
1 Like

I dont know why but It doesnt work. Again, no errors in output.
Btw this Is the whole script:

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


--//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
		for _, conf in workspace.ConfettiGiver:GetChildren() do
			conf.Enabled = true
			task.delay(10,function()
				conf.Enabled = false
			end)
		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

:tired_face: I dont understand why it doesnt work!

Well I can’t spot anything obviously wrong. Try using the debugger. Put some breakpoints on relevant lines of code by clicking in the gutter to make red circles appear (right click to delete them):
image

Then run your game and it should pause on every line of code with a breakpoint. You can then use the debugger controls to step through your code one statement at a time:

image

You can also enable the Watch window to inspect variables during execution:

image

That way you can see if your script follows the expected control flow and/or if the variables have the expected values. It might take a while but this is a sure fire way to narrow down the issue.

1 Like

Thank you so much! I got the issue :hugs:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.