Attempt to index nil with 'Wait'?

Everytime I try to wait for a sound effect to end this happens, any help?

This is my code

local tween = tweenservice:Create(cam, TweenInfo.new(0.4), {["CFrame"] = senpaicam.CFrame})
cam.CameraType = "Scriptable"
	wait(0.4)
	sfx:Play()
	tween:Play()
	tween.Completed:Wait()
	sfxkill[math.random(1, #sfxkill)]:Play()
	wait(5)
	nowait:Play()
	wait(3.8)
	ayanosoundloc.GameOver:Play()
	wait(3.7)
	sfxayano[math.random(1, #sfxayano)]:Play()
	sfxayano.Ended:Wait()
	ayanosoundloc.GameOverTheme:Play()

Any help?

1 Like

Which line does it say the error on?

Theres a possibility that its not a tween object inside the list, but not enough context to understand

sfxayano.Ended:Wait() is the line that errors

You are basically telling a table to wait until it ends, and Wait isn’t a function within a table so I’m not sure what you expect.

Oh, well is there any way that I can wait until a randomly selected sound effect ends?

Yes:

local RandomSound = sfxayano[math.random(1, #sfxayano)] -- gets Random Instance
RandomSound:Play() -- Plays Instance
RandomSound.Ended:Wait() -- Waits until Sound ends

Doing this:

local RandomSound = sfxayano[math.random(1, #sfxayano)]:Play()

will potentially make the code Error or return nil on the Variable.

1 Like

Thank worked! Thank you very much!

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