You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I am attempted to create a script where, if a player presses the union button once, it starts a looped alarm sound. When they press it again, it stops the alarm sound.
What is the issue?
When I attempt to click the button in-game, nothing happens. Nothing in the output log either.
What solutions have you tried so far?
I have fixed all the output errors, and now that there aren’t any; I tried changing the click detector from a function to an if statement.
local alarm = script.Parent.Alarm
local button = script.Parent.Button
if script.Parent.Button.ClickDetector.MouseClick then
wait(0.2)
if alarm.IsPlaying == false then
alarm.Playing = true
end
if alarm.IsPlaying == true then
alarm.Playing = false
end
end
Since there is no output, could I have made a crucial typo or command mistake?
You should do this instead of putting the ClickDetector event in an if statement:
local alarm = script.Parent.Alarm
local button = script.Parent.Button
script.Parent.Button.ClickDetector.MouseClick:Connect(function()
wait(0.2)
if alarm.IsPlaying == false then
alarm.Playing = true
end
if alarm.IsPlaying == true then
alarm.Playing = false
end
end)
You can’t do that in an if statement try the script that I gave you.
The code you have written only runs once. It goes through the sequence and then completes. Instead do what @Nerkonl has mentioned and tie the code to an event. Events run a provided function every time it is occured, all you have to do is “Connect” the function to the event.
I replaced, it still does not seem to work. No output error.
Current script:
local alarm = script.Parent.Alarm
local button = script.Parent.Button
script.Parent.Button.ClickDetector.MouseClick:Connect(function()
wait(0.2)
if alarm.IsPlaying == false then
alarm:Play()
end
if alarm.IsPlaying == true then
alarm:Stop()
end
end)```
You have a ClickDetector in the Button part, I assume. Have you checked the properties of that ClickDetector? It may be disabled or have a really really short Click Distance.