Attempt to call a nil value on 2 int values?

code:

local phase = workspace.Minigame1.Phase
phase.Value = 1
local debounce = false
local tapedebounce = false
local songs = workspace.Minigame1.Songs
game:GetService("ContentProvider"):PreloadAsync(songs:GetChildren())
currentsongcounter = workspace.Minigame1.CurrentSongCounter.Value
local currentsong = songs.Song1
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()
	task.spawn(function()
	if not tapedebounce then
		print(currentsong)
		task	.wait(math.random(1, currentsong.TimeLength))
			if math.random(1,10) == 1 and not debounce then
			print("moved during the song")
			phase.Value += 1
			debounce = true
			task.wait(15)
				debounce = false
			end
		end
		end)
		tape.TapePlay:Play()
		print(tapedebounce)
		tape.Color = Color3.fromRGB(255)
		tape.Parent.Screen.Color = Color3.fromRGB(255, 255, 255)
		tapedebounce = true
		songstable[currentsongcounter]()
		currentsong.Ended:Connect(function()
			tape.TapeStop:Play()
			tape.Color = Color3.fromRGB(0,255)
			tape.Parent.Screen.Color = Color3.fromRGB()
		tapedebounce = false
		if not debounce and math.random(1,2) == 1 then
				print("moved after the song")
				debounce = true
				phase.Value += 1
				task.delay(5, function()
					debounce = false
			end)
		end
	end)
end)

ok so the problems are here:

songstable[currentsongcounter]()
animations[phase.Value]()

for some reason they just error even though they are CLEARLY defined???

1 Like

I think your indexes are going out of bounds. You should set your debounce immediately after checking it i.e.:

if not tapedebounce then
   tapedebounce = true
...
1 Like

it was but changing stuff pushed it down. how would that help though? still trying

Because spam clicking the button will allow the top logic to be entered multiple times because the tapedebounce is being set after possibly a 15 second task.wait() in the code above it.

yeah it seems like you can. still have no clue how to fix the errors.

I think they are being incremented past their limits. Check the value after incrementing them and if they are out of bounds reset them to the first index. i.e.

phase.Value += 1
if phase.Value > 2 then phase.Value = 1 end

etc.

1 Like

kinda odd but imma try.
asdasdasdas

It could be failing logic in the function body. My guess from the errors is that you are calling animations[phase.Value]() with an index greater than 2. Same for the other table accessor.

may have kinda fixed it. i’ll try to break stuff

nvm veuh i harewqheklh i hate errorssssss .