For some reason when I do Click = not Clicked it won’t make it back to false meaning My siren sound won’t stop. On the first click it will make it true and siren will play but on the second click it isn’t stopping my siren sound
local Button = script.Parent
local Clicked = false
Button.MouseButton1Down:Connect(function()
Clicked = not Clicked
if Clicked == true then
game.ReplicatedStorage.Siren:FireServer()
if Clicked == false then
game.ReplicatedStorage.Sirenstop:FireServer()
end
end
end)
Your if statement checking if Clicked is equal to false is nested inside your other if statement that checks if Clicked is true, meaning that in reality you are only checking if Clicked is equal to true. Move your other if statement outside and then try again.
Button.MouseButton1Down:Connect(function()
Clicked = not Clicked
if Clicked == true then
game.ReplicatedStorage.Siren:FireServer()
end
if Clicked == false then
game.ReplicatedStorage.Sirenstop:FireServer()
end
end)
local Button = script.Parent
Clicked = false
Button.MouseButton1Down:Connect(function()
if Clicked == false then
Clicked = true
else
Clicked = false
end
if Clicked == true then
game.ReplicatedStorage.Siren:FireServer()
else
game.ReplicatedStorage.Sirenstop:FireServer()
end
end)
You don’t actually need two remote-events for pausing and unpausing sirens! Try using something like this:
-- Toggle
local Button = script.Parent
local Siren = game:GetService('ReplicatedStorage'):WaitForChild('Siren');
Button.MouseButton1Down:Connect(function()
Siren:FireServer()
end);
-- RemoteEvent
local Siren = game:GetService('ReplicatedStorage'):WaitForChild('Siren');
local SirenAudio -- put directory here
Siren.OnServerEvent:Connect(function()
SirenAudio.Playing = not SirenAudio.Playing
end)