Is there a way to restart a function in lua without recalling the function itself?

worked but a problem i am experiencing is that i have to double click to play music 1.

local music1 = game.Workspace.MiiChannelMusic
local music2 = game.Workspace.DoubleCherryPass
local musicplayer = game.StarterGui.ScreenGui.musicplayer
local clickCount = 0

local function onClicked()
	if clickCount == 0 then
		music1.Playing = false
		music2.Playing = false
	elseif clickCount == 1 then
		music2.Playing = false
		music1.Playing = true
	elseif clickCount == 2 then
		music1.Playing = false
		music2.Playing = true
		
	end
	clickCount = (clickCount + 1) % 3
end


script.Parent.MouseButton1Click:Connect(onClicked)

When You declare the variable clickCount, set it to 1 instead of 0.

1 Like

getting more problems than errors. when i set click count to one and leave all the other numbers as the same, i have to double/triple click to play music2, and music1 never plays.

when i set it to one but increase numbers in the function up by one also, i have to double/triple click to play song 1, but song 2 never plays