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:

01local Switched = script.Parent.Switched
02 
03function onClicked()
04 
05    if Switched == false then
06        Switched = true
07    script.Parent.On:Play()
08    wait(0.5)
09    script.Parent.Off:Play()
10    wait(0.2)
11        Switched = false
12end
13 
14 
15end
16 
17script.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;

01local Switched = false -- You can't change a Objects value. Unless Switch is a BoolValue
02local CD = script.Parent:WaitForChild('ClickDetector') --The ClickDetector
03local On = script.Parent:WaitForChild('On') --On
04local Off = script.Parent:WaitForChild('Off') -- Off
05CD.MouseDown:Connect(function() --You can use MouseDown
06    if Switched == false then
07        Switched = true
08        On:Play()
09        wait(0.5)
10        Off:Play()
11        wait(0.2)
12        Switched = false
13    end
14end)

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