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

how do i make the brick change color on click and make the sound stop playing if clicked again?

Asked by 3 years ago

function onclicked() script.Parent.ClickDetector.MaxActivationDistance = 0 script.Parent.ClickSound.Playing = true wait(6) script.Parent.ClickDetector.MaxActivationDistance = 32 script.Parent.ClickDetector.BrickColor = [212,0,0] end script.Parent.ClickDetector.MouseClick:Connect(onclicked) i tried making it so the brick changes colour upon clicking the brick and it does nothing i'm still new to scripting and idk where to place it and i also tried adding the same script to another block but idk how to disable it

2 answers

Log in to vote
1
Answered by
imacodr 40
3 years ago

To change the color of a brick correctly you need to use the Color3 method. If you are using a RGB color you can also use Color3.fromRGB(x,y,z).

As for the sound stop playing after clicking again you can add a debounce.

In the end your script would be:

local status = false

function onclicked() 
    if status == false then
        script.Parent.ClickDetector.MaxActivationDistance = 0 
        script.Parent.ClickSound.Playing = true 
        wait(6)                                  
                script.Parent.ClickDetector.MaxActivationDistance = 32 
        script.Parent.ClickDetector.BrickColor = Color3.new(212,0,0) -- or Color3.fromRGB
        status = true
    end

    if status == true then
        -- Stop playing and do the rest
    end

end 

script.Parent.ClickDetector.MouseClick:Connect(onclicked) 
Ad
Log in to vote
0
Answered by
notfenv 171
3 years ago

j

local Toggled = false

function OnClicked()
    if not Toggled then
        -- Alternatively, you can use Color3.fromRGB(212, 0, 0) instead. Color 3 values must utilise / 255 unless you're big brain.
        Toggled = true
        script.Parent.ClickDetector.MaxActivationDistance = 0
        script.Parent.ClickSound:Play()
        wait(6)
        script.Parent.ClickDetector.MaxActivationDistance = 32
        script.Parent.ClickDetector.BrickColor = Color3.new(212 / 255, 0, 0)
    else
        Toggled = false
        script.Parent.ClickSound:Stop()
    end
end

script.Parent.ClickDetector.MouseClick:Connect(OnClicked)

Answer this question