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

How do I see if a ClickDetector has been clicked within a certain amount of time?

Asked by
Nidoxs 190
9 years ago

So I have a lever and when you pull it, it makes a sound. But I want it to play a special sound only when it gets clicked within 1 second. How would I do this? Here is what I have so far:

function matlever() -- manages the whole demat / move / mat thing
    if script.Parent.Variables.Power.Value == true and script.Parent.Variables.Override.Value == false then
        if status.Value == 0 then
            status.Value = 1
            if converted == true then
                script.Parent.Variables.rdoor.Value = true
            end
            matleversound:Play()
            local g = script.Parent.Controls.Matlever.Land:GetChildren()
            for i = 1,#g do
                g[i].Transparency = 0
                g[i].CanCollide = true
            end
            local g = script.Parent.Controls.Matlever.Fly:GetChildren()
            for i = 1,#g do
                g[i].Transparency = 1
                g[i].CanCollide = false
            end
            fly.Value = true
            demat()
            move()
        elseif status.Value == 2 then
            status.Value = 3
            matleversound:Play()
            local g = script.Parent.Controls.Matlever.Land:GetChildren()
            for i = 1,#g do
                g[i].Transparency = 1
                g[i].CanCollide = false
            end
            local g = script.Parent.Controls.Matlever.Fly:GetChildren()
            for i = 1,#g do
                g[i].Transparency = 0
                g[i].CanCollide = true
            end
            move()
            repeat
                wait(0.1)
            until script.Parent.Variables.ExtChange.Value == false
            mat()
            fly.Value = false
            status.Value = 0
            if converted == true then
                script.Parent.Variables.rdoor.Value = false
            end
        end
    end
end 

script.Parent.Controls.Matlever.Fly.Fly.ClickDetector.MouseClick:connect(matlever)
script.Parent.Controls.Matlever.Land.Land.ClickDetector.MouseClick:connect(matlever)

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

You need to make the script wait until a second has passed...there's a name for this but I can't remember it. Anyways, I added the variable 'Able'. It makes the function only pass if 'Able' is set to true...This should work anyways, leave a comment if not. Hope I helped :P

Able=true
function matlever() -- manages the whole demat / move / mat thing
if Able==true then
Able=false
    if script.Parent.Variables.Power.Value == true and script.Parent.Variables.Override.Value == false then
        if status.Value == 0 then
            status.Value = 1
            if converted == true then
                script.Parent.Variables.rdoor.Value = true
            end
            matleversound:Play()
            local g = script.Parent.Controls.Matlever.Land:GetChildren()
            for i = 1,#g do
                g[i].Transparency = 0
                g[i].CanCollide = true
            end
            local g = script.Parent.Controls.Matlever.Fly:GetChildren()
            for i = 1,#g do
                g[i].Transparency = 1
                g[i].CanCollide = false
            end
            fly.Value = true
            demat()
            move()
        elseif status.Value == 2 then
            status.Value = 3
            matleversound:Play()
            local g = script.Parent.Controls.Matlever.Land:GetChildren()
            for i = 1,#g do
                g[i].Transparency = 1
                g[i].CanCollide = false
            end
            local g = script.Parent.Controls.Matlever.Fly:GetChildren()
            for i = 1,#g do
                g[i].Transparency = 0
                g[i].CanCollide = true
            end
            move()
            repeat
                wait(0.1)
            until script.Parent.Variables.ExtChange.Value == false
            mat()
            fly.Value = false
            status.Value = 0
            if converted == true then
                script.Parent.Variables.rdoor.Value = false
            end
        end
    end
if Able=false then
wait(1)
Able=true
end
end
end 

script.Parent.Controls.Matlever.Fly.Fly.ClickDetector.MouseClick:connect(matlever)
script.Parent.Controls.Matlever.Land.Land.ClickDetector.MouseClick:connect(matlever)
0
How would I play the sound if It is clicked within 1 second? And: if function==true then is underlined red on my script. Nidoxs 190 — 9y
0
Oh, sorry. I fixed it. It wasn't supposed to say function. It was supposed to say "Able". dyler3 1510 — 9y
Ad

Answer this question