Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

4 comments

0

You're retrieving the object, then checking if it's "false". e-e

0

How would I fix it then?

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.

0

Its fine, i fixed it myself by making the ClickDetector MaxActivationDistance 0 until it's done the clicking noise.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.