Stupid table won't work without any errors my god

the songtable will not run! only issue. debounce works and everything else works. just that table will not work and i am getting NO errors. the counter does not go up either.
code:

for _, songs in pairs(workspace.Minigame1.Songs:GetChildren()) do
	game:GetService("ContentProvider"):PreloadAsync({songs})
end
local phase = workspace.Minigame1.Phase
phase.Value = 1
local debounce = false
local tapedebounce = false
local songs = workspace.Minigame1.Songs
currentsongcounter = workspace.Minigame1.CurrentSongCounter.Value
local currentsong
local anim
local songstable = {
	[1] = function()
		songs.Song1:Play()
		currentsongcounter += 1
		currentsong = songs.Song1
	end,
	[2] = function ()
		songs.Song2:Play()
		currentsongcounter += 1
		currentsong = songs.Song2
	end,
	[3] = function ()
		songs.Song3:Play()
		currentsongcounter += 1
		currentsong = songs.Song3
	end,
	[4] = function ()
		songs.Song4:Play()
		currentsongcounter += 1
		currentsong = songs.Song4
	end,
	[5] = function ()
		songs.Song5:Play()
		currentsongcounter += 1
		currentsong = songs.Song5
	end,
	[6] = function ()
		songs.Song6:Play()
		currentsongcounter += 1
		currentsong = songs.Song6
	end
}
local animations = {
	[1] = function()
		script.Parent.Animations.AnimationId = "rbxassetid://13142014107"
	end,
	[2] = function()
		script.Parent.Animations.AnimationId = "rbxassetid://130321654403"
		anim.Stopped:Connect(function()
			script.Parent.Animations.AnimationId = "rbxassetid://13144460557"
		end)
		
	end
}
local function updateanimation()
	animations[phase.Value]()
	anim = script.Parent.Humanoid:LoadAnimation(script.Parent.Animations)
	anim:Play()
end
updateanimation()
phase:GetPropertyChangedSignal("Value"):Connect(updateanimation)
local tape = workspace.Minigame1.TapePlayer.Button
tape.ClickDetector.MouseClick:Connect(function()
	if not tapedebounce then
		print(tapedebounce)
		tapedebounce = true
		songstable[currentsongcounter]()
		currentsong.Ended:Connect(function()
			tapedebounce = false
		end)
	else
		print(tapedebounce)
	end
end)

i hate silent bugs SO much

You should use a Array Table Instead of a Dictionarie table

why though? also please give me a snippet since i am still bad at table words lol

The “currentsongcounter += 1” Should be “currentsongcounter = currentsongcounter + 1”. Secondly “local debounce = false” is a reference to a non-existent property. Try this Script Instead and let me know if it works:

for _, songs in pairs(workspace.Minigame1.Songs:GetChildren()) do
    game:GetService("ContentProvider"):PreloadAsync({songs.Sound.SoundId})
end

local phase = workspace.Minigame1.Phase
phase.Value = 1

local currentsongcounter = workspace.Minigame1.CurrentSongCounter.Value
local currentsong
local anim

local songs = workspace.Minigame1.Songs
local songstable = {
    [1] = function()
        songs.Song1:Play()
        currentsongcounter = currentsongcounter + 1
        currentsong = songs.Song1
    end,
    [2] = function ()
        songs.Song2:Play()
        currentsongcounter = currentsongcounter + 1
        currentsong = songs.Song2
    end,
    [3] = function ()
        songs.Song3:Play()
        currentsongcounter = currentsongcounter + 1
        currentsong = songs.Song3
    end,
    [4] = function ()
        songs.Song4:Play()
        currentsongcounter = currentsongcounter + 1
        currentsong = songs.Song4
    end,
    [5] = function ()
        songs.Song5:Play()
        currentsongcounter = currentsongcounter + 1
        currentsong = songs.Song5
    end,
    [6] = function ()
        songs.Song6:Play()
        currentsongcounter = currentsongcounter + 1
        currentsong = songs.Song6
    end
}

local animations = {
    [1] = function()
        script.Parent.Animations.AnimationId = "rbxassetid://13142014107"
    end,
    [2] = function()
        script.Parent.Animations.AnimationId = "rbxassetid://130321654403"
        anim.Stopped:Connect(function()
            script.Parent.Animations.AnimationId = "rbxassetid://13144460557"
        end)
    end
}

local function updateanimation()
    animations[phase.Value]()
    anim = script.Parent.Humanoid:LoadAnimation(script.Parent.Animations)
    anim:Play()
end

updateanimation()
phase:GetPropertyChangedSignal("Value"):Connect(updateanimation)

local tape = workspace.Minigame1.TapePlayer.Button
local tapedebounce = false
tape.ClickDetector.MouseClick:Connect(function()
    if not tapedebounce then
        tapedebounce = true
        songstable[currentsongcounter]()
        currentsong.Ended:Connect(function()
            tapedebounce = false
        end)
    end
end)

ahem… what?
+= is the literal same thing
local debounce = false is literally just a bool variable???
did you mean that it’s not used? the script is just unfinished.

1 Like

It isn’t the same thing, just try the new script.

it literally is??? they ARE the same thing. and you took out the debounce i was going to use.

just as i suspected, literally same thing.

oh btw

Not sure what the issue is as it’s a bit too late for me to look into it more, but I just wanted to say that you can do this all without an array at all with something like this:

tape.ClickDetector.MouseClick:Connect(function()
	if not tapedebounce then
		tapedebounce = true
		local currentSong = songs[`Song{currentsongcounter}`]
		currentSong:Play()
		currentSong.Ended:Wait()
		currentSong = nil
		currentsongcounter += 1
		if currentsongcounter > 6 then
			currentsongcounter = 1
		end
		tapedebounce = nil
	end
end)

Also not that it matters, you but you don’t need to declare variables as false, you can keep them empty. On that note, it’s also good practice to use something like camelCase to improve readability, but that too is obviously optional.

Thanks for replying. I’m not sure if that’ll fix it but I’ll try whenever i can anyways. The issue is that everything works fine, but when the songstable is used, no song plays nor does the counter EVER go up. I usually use PascalCase but i don’t use it on little scripts such as this one since it’s a mini game, this game is supposed to be updated a few times to fix bugs and I’m the lead and only programmer working on it lol. Thank you, though. I’ll test it when I can. Btw sorry if it came off rude, if it did, i didn’t mean to make it sound rude.

Just to give you a bit of (hopefully helpful) information - I stripped back your code and tested the table as it is and it works as expected so I think your focusing on the wrong area of your script to fix your problem.
Just for clarity - I used 3 songs in a folder so I only used 3 table entries for testing
Stripped down code that works as expected:

local songs = workspace.Songs
game:GetService("ContentProvider"):PreloadAsync(songs:GetChildren())

currentsongcounter = 1
local currentsong
local anim
local songstable = {
	[1] = function()
		songs.Song1:Play()
		currentsongcounter += 1
		currentsong = songs.Song1
	end,
	[2] = function ()
		songs.Song2:Play()
		currentsongcounter += 1
		currentsong = songs.Song2
	end,
	[3] = function ()
		songs.Song3:Play()
		currentsongcounter += 1
		currentsong = songs.Song3
	end

}

songstable[currentsongcounter]()
print(currentsongcounter)

task.wait(5)
songstable[currentsongcounter]()
print(currentsongcounter)

Audio plays correctly and counter goes up as expected.
Output (printing currentsongcounter)

2 - Server - Script:27
3 - Server - Script:31

1 Like

I just realized my dumb brain did a for loop to preload each song even tho u need a table for it too omg :sob::sob::sob:
I’ll also try to just have it do a wait to start the table and if that doesn’t work I’ll shrivel and die

1 Like

I AM SO DUMB I DIDN’T FRIGGING SET THE ID FOR THE SONGS I THOUGHT I DID I AM SORRY
ASDASDAsadsada