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

How i make a sound play when i press this button?

I have this script, But idk how to add a sound play function when i press the button, someone can help? Thanks


function ToggleLight()
	if script.Parent.Parent.Parent.LightState.Value == false then
		script.Parent.Parent.Parent.LightState.Value = true
		script.Parent.BrickColor = BrickColor.new("Bright green")
		for i = 1, lights do
			script.Parent.Parent.Parent:FindFirstChild("Lamp" .. i).Light.Material = Enum.Material.Neon
			script.Parent.Parent.Parent:FindFirstChild("Lamp" .. i).Light.SpotLight.Enabled = true
			if script.Parent.Parent.Parent:FindFirstChild("Lamp" .. i) == nil then break end
		end
	else
		script.Parent.Parent.Parent.LightState.Value = false
		script.Parent.BrickColor = BrickColor.new("Bright red")
		for i = 1, lights do
			script.Parent.Parent.Parent:FindFirstChild("Lamp" .. i).Light.Material = Enum.Material.Plastic
			script.Parent.Parent.Parent:FindFirstChild("Lamp" .. i).Light.SpotLight.Enabled = false
			if script.Parent.Parent.Parent:FindFirstChild("Lamp" .. i) == nil then break end
		end
	end
end

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

1 answer

✓ Accepted answer

Sounds have a method called Play that you can use to play them. Example usage:

Light.Sound:Play()

1 comment

0

Thank you so much!

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