Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Simple function to play a sound does not work?

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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.

Ad

Answer this question