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

why am I not able to Connect the functions here?

Asked by
Vlym 19
4 years ago
local sirenOn = game.Workspace.SirenOn
local sirenOff = game.Workspace.SirenOff
local lockDown = game.Workspace.LockDown
local alarm = game.Workspace.Alarm

while wait(0.2) do
    if lockDown.Status.Value == true then
        print("yeet")

        sirenOff.ClickDetector.MouseClick:Connect(StopSiren)
        print("function called")

        sirenOn.ClickDetector.MouseClick:Connect(PlaySiren)
    end
end


function PlaySiren()
    alarm.Sound:Play()
end

function StopSiren()
    alarm.Sound:Stop()  
end

Error: 21:12:26.685 - Attempt to connect failed: Passed value is not a function

0
Try putting the functions before you call them, like physically place them above the while loop. cowsoncows 951 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

Because the functions you made to play or stop the Siren are placed after the loop. You need to place both of them before so that your loop can recognize them.

Like This,

local sirenOn = game.Workspace.SirenOn
local sirenOff = game.Workspace.SirenOff
local lockDown = game.Workspace.LockDown
local alarm = game.Workspace.Alarm

function PlaySiren()
    alarm.Sound:Play()
end

function StopSiren()
    alarm.Sound:Stop()  
end

while wait(0.2) do
    if lockDown.Status.Value == true then
        print("yeet")

        sirenOff.ClickDetector.MouseClick:Connect(StopSiren)
        print("function called")

        sirenOn.ClickDetector.MouseClick:Connect(PlaySiren)
    end
end

Hope this helped! -Swifty

0
There's no point in having a loop. Azarth 3141 — 4y
Ad
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
4 years ago
-- You can shorten game.Workspace to workspace
local sirenOn = workspace.SirenOn
local sirenOff = workspace.SirenOff
local lockDown = workspace.LockDown
local alarm = workspace.Alarm

-- Anonymous functions, you don't need a loop. 
sirenOn.ClickDetector.MouseClick:Connect(function()
    if not lockDown.Status.Value then 
        alarm.Sound:Play()
    end
end)

sirenOff.ClickDetector.MouseClick:Connect(function()
    if lockDown.Status.Value then 
        alarm.Sound:Stop()
    end
end)

Answer this question