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

Can someone please help me find out what's wrong with it? Everything looks fine to me.

Asked by 7 years ago

I made a script in which I press a button and then it makes a noise, and then another noise. Here's my script:

local Switched = script.Parent.Switched

function onClicked()

    if Switched == false then
        Switched = true
    script.Parent.On:Play()
    wait(0.5)
    script.Parent.Off:Play()
    wait(0.2)
        Switched = false
end


end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
You're retrieving the object, then checking if it's "false". e-e TheeDeathCaster 2368 — 7y
0
How would I fix it then? Loleydude 29 — 7y
0
You would use the WaitForChild function to yield the code until it exists, but are you trying to check if the GUI is visible? Your question is very vague on information. TheeDeathCaster 2368 — 7y
0
Its fine, i fixed it myself by making the ClickDetector MaxActivationDistance 0 until it's done the clicking noise. Loleydude 29 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Here's a nice fix;

local Switched = false -- You can't change a Objects value. Unless Switch is a BoolValue
local CD = script.Parent:WaitForChild('ClickDetector') --The ClickDetector
local On = script.Parent:WaitForChild('On') --On
local Off = script.Parent:WaitForChild('Off') -- Off
CD.MouseDown:Connect(function() --You can use MouseDown
    if Switched == false then
        Switched = true
        On:Play()
        wait(0.5)
        Off:Play()
        wait(0.2)
        Switched = false
    end
end)

This should work, though I was not sure what Switched Was because there was no value.

If this helped then please accept answer :D

Ad

Answer this question