Play is not a valid member of Script "Workspace.Cheezburger.Part.Sound"

Can someone help please???

Part = script.Parent
Sound = Part.Sound

function onClicked()
	Sound:Play()
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

image
image

You named your script Sound, try to avoid duplicate names to avoid this issue.

3 Likes

The script is also named Sound so it finds the script first and ends up trying to do :Play() on the script.

1 Like

Basically, because inside the Part there are two objects with the name sound, your script is identifying the script. Change the sound of either object.

1 Like

dam i didnt noticed that lol thank you

1 Like
local Part = script.Parent
local Sound = Part:WaitForChild("Sound")

function onClicked()
	Sound:Play()
end

script.Parent:WaitForChild("ClickDetector").MouseClick:connect(onClicked)

What the previous posts suggested, rename the script to “Script” as it would be by default, additionally I’ve added a couple of waits (this is to allow for the requested instances to load before the script is executed), finally you should declare variables locally, here’s why:

Local variables are obtained faster than global variables because they’re integrated into the environment in which they were created. If possible, you should always use local variables over global variables, unless there’s a specific reason otherwise.