Attempt to index nil with 'Connect'

I am making a continuation of my last post and am trying a solution with a .Changed event in a local script.

The problem is that I get this error:

Script:

script.Parent.Sound.SoundId.Changed:Connect()
script.Parent.Sound:Stop()
wait(.1)
script.Parent.Sound:Play()

(For context, the changed event fires when the SoundId of the sound in the GUI changes, which is triggered from a part being touched.)

The script is located here:
image

1 Like

SoundId is a property, so you can’t use Changed on it. Instead, you GetPropertyChangedSignal

script.Praent.Sound:GetPropertyChangedSignal("SoundId"):Connect(function()
    -- didnt know that connect doesnt accept nil values oops
end)

Edit: Fixed code

1 Like

.Changed is an event of an instance, not it’s properties. Also, your not connecting any functions to the changed event

I am now getting this error:
image

This is my updated script.

script.Parent.Sound:GetPropertyChangedSignal("SoundId"):Connect()
script.Parent.Sound:Stop()
wait(.1)
script.Parent.Sound:Play()

This is because you didn’t connect any function to it…

I have connected a function now and gotten the script to work. Thank you.