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

how to make a different audio play when button is pressed again? [almost solved]

Asked by 3 years ago
Edited 3 years ago

so i have this nightvision script and i want to make the de activate sound to play when the player clicks on the button again

my script:

script.Parent.ClickBox.MouseButton1Click:Connect(function()
    script.Parent.Activate:Play()
    game.Lighting.NightVisionColor.Enabled = not game.Lighting.NightVisionColor.Enabled

end)

so i made it thanks and it works but i made a diffrent one with key binds and it dosent seem to work

local UserInputService = game:GetService("UserInputService")
local actoov  = false

local function onInputBegan(input, gameProcessed)
    if input.UserInputType == Enum.KeyCode.Y then
    game.Lighting.NightVisionColor.Enabled = not game.Lighting.NightVisionColor.Enabled

    if actoov == false then
        script.Parent.Activate:Play()
        actoov = true

    elseif actoov == true then
    script.Parent.Deactivate:Play()
    actoov = false
        end
        end

    UserInputService.InputBegan:Connect(onInputBegan)
end








1 answer

Log in to vote
0
Answered by 3 years ago

you can make a variable = true(or false, its up to you, really doesn’t matter) and u can write something similar to this ( i’m a script rookie so maybe i’m wrong):

local Hotdogs = false

script.Parent.ClickBox.MouseButton1Click:Connect(function()
if Hotdogs == false then
play your sound
Hotdogs = true

elseif Hotdogs == true then
play the other sound
Hotdogs = false
end

end)
Ad

Answer this question