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

Simple function to play a sound does not work?

I am making a simple script that when you activate the prompt, it plays a sound and changes the color of the screen (basically turning it on). When you click it again, it turns it off.

EDIT: I fixed the issue, but now, once you turn it off, it doesn't turn back on!

local Sound1 = script.Parent:WaitForChild("monitor_on")
local Sound2 = script.Parent:WaitForChild("monitor_off")
local Sound3 = script.Parent:WaitForChild("comp_windup")
local screenOn = true

local function onPromptTriggered(player)
	if screenOn then
		Sound1:Play()
		wait(0.1)
		Sound3:Play()
		script.Parent.BrickColor = BrickColor.new(58/255, 125/255, 21/255)
		script.Parent.ProximityPrompt.ObjectText = "Turn Off!"
	else
		Sound1:Stop()
		Sound3:Stop()
		Sound2:Play()
		script.Parent.BrickColor = BrickColor.new(17/255, 17/255, 17/255)
		script.Parent.ProximityPrompt.ObjectText = "Turn On!"
	end
	screenOn = false
end

script.Parent.ProximityPrompt.Triggered:Connect(onPromptTriggered)

1 answer

I fixed all issues with the script! The issue at first was instead of using BrickColor.new, I had just put BrickColor = "ColorHere". I learned that using the format of (0/255,0/255,0/255) works instead.

The next issue I fixed was the screen not turning back on after being turned off, and that was simply because I had screenOn = false when instead it should be screenOn = not screenOn.

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