How do I make this script work?

It’s supposed to play the click sound but it isn’t working and I think it’s because I didn’t script it correctly. How do I fix the code?

local Sound = script.Parent.Parent.Sound 

script.Parent.Parent.MouseButton1Click:Connect(function()
	Sound:Play()
end)

4 Likes

Check the .Playing property of the Sound object in-game when you click the button.

2 Likes

Doesn’t work I think it has something to do with the script

1 Like

Hello try change name of the button because if your button name “sound” the script exucution will have some probelm the script don’t know you mean the sound effect or button named sound.

1 Like

Insert a print() statement into your function to check if it runs.

It’s a local script. Try to make a basic script and to play a sound use a remove event.

what does this mean?

Hello!

It’s this line that’s causing the problem, which is the reason you are getting the error.
You are saying that the Sound you are trying to access is parented to the “a” ImageButton when it is actually a child of the TextButton.
Change that line to this:

local Sound = script.Parent:WaitForChild("Sound")

script.Parent.MouseButton1Click:Connect(function()
Sound:Play()
end)

Hope this helps!

1 Like

or maybe just put check if the game isloaded if not wait for it
something like this :

if not game:IsLoaded() then game.Loaded:Wait() end

local Sound = script.Parent.Sound 

script.Parent.MouseButton1Click:Connect(function()
	Sound:Play()
end)
2 Likes