Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Huh? Attempt to index upvalue 'AlarmSound1' (a nil value)?

So, this error popped up on a script that i wrote

Workspace.Model.EventLister:20: attempt to index upvalue 'AlarmSound1' (a nil value)

I'm not sure what it means. Might be because i'm Dutch.

So, this is the simple script:

local AlarmSound1 = script.Parent:FindFirstChild("LockdownAlarm1")
local AlarmSound2 = script.Parent:FindFirstChild("LockdownAlarm2")
local AlarmSound3 = script.Parent:FindFirstChild("LockdownAlarm3")
local AlarmSound4 = script.Parent:FindFirstChild("LockdownAlarm4")
local AlarmSound5 = script.Parent:FindFirstChild("LockdownAlarm5")
--script.Parent.AlarmLight1.Light.LockdownAlarm1:Play() -- **THIS WORKED**

SetOn.Event:Connect(function()
	wait()
	AlarmSound1:Play() --** AND HERE COMES THE ERROR**
	AlarmSound2:Play()
	AlarmSound3:Play()
	AlarmSound4:Play()
	AlarmSound5:Play()
	FadeOnLights()	
	repeat
		wait()
	until AlarmSound1.TimePosition >= 2
	FadeOnLights()	
	repeat
		wait()
	until AlarmSound1.TimePosition >= 4
	FadeOnLights()
	repeat
		wait()
	until AlarmSound1.TimePosition >= 6
	FadeOnLights()
end)

Any best man who could explain me what i'm doing wrong? Yes, i really need 5 sounds :-).

Edit: Added Local in front to the FindFirstChild's. Is this good or bad?

Edit 2: Replacing FindFirstChild for WaitForChild gives this error:

Infinite yield possible on 'Workspace.Model:WaitForChild("LockdownAlarm1")'

Edit 3: changed :WaitForChild("LockdownAlarm1") to :WaitForChild("LockdownAlarm1", true)

But, nothing happens. The script stops running after line 9 (where it's going to look for Lockdownalarm1). Also, the event won't be triggered now.

2 comments

0

'script.Parent:FindFirstChild("LockdownAlarm1")' does not exist. This could be because the script executes that chunk of code before that object loads in. Try waiting for the object with WaitForChild instead.

0

It already has to wait quiete long before it gets activated. Also, WaitForChild gives also an error (See my post, edited it)

2 answers

✓ Accepted answer

You need to have FindFirstChild recursive, so instead of

script.Parent:FindFirstChild("LockdownAlarm1")

it would be

script.Parent:FindFirstChild("LockdownAlarm1", true)

5 comments

0

I've done that. And nothing happens. The script stops running after line 9. Even the Event doesn't work now...

0

That probably means that "LockdownAlarm1" is not a thing. Do you still have the "waitforchild" thing? if so, remove that. That was bad advice from the person above.

0

Thank you my lord. It still was WaitForChild indeed. I've chaned it to Find and now it works :-) THANK YOU VERY MUCH!

0

No problem :)

0

No problem :)

Try replace FindFirstChild with WaitForChild

1 comment

0

Then it gives me this error: Infinite yield possible on 'Workspace.Model:WaitForChild("LockdownAlarm1")'

This discussion is preserved as it was. New answers, comments, and votes are closed.