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

Why does my function get trigger multiple times?

Asked by 2 years ago

I made a function that will spawn pipes every 3.5 sec:

local function MakePillar()
    while dead == false do
        local newNum = Center()


        local model = Instance.new("Model",game.Workspace.PillarsFolder)
        model.Name = "Pillars"

        local newPillar = Pillar:Clone()
        newPillar.Name = "newPillar"
        newPillar.Parent = model

        newPillar.Size = Vector3.new(3,newNum -Distance,3)
        newPillar.Position = Vector3.new(offset,newPillar.Size.Y/2 - Distance,0)
        points[1] = newPillar

        local newPillar2 = Pillar:Clone()
        newPillar2.Name = "newPillar2"
        newPillar2.Parent = model

        newPillar2.Size = Vector3.new(3,27 - newNum - Distance,3)
        newPillar2.Position = Vector3.new(offset,(27 - newPillar2.Size.Y/2)+Distance,0)
        points[2] = newPillar2


        for i = 1, #points do
            tweenPart(points[i], 15, {Position = points[i].Position - Vector3.new(60,0,0)})
        end
        wait(3.5)
    end
end

and here is the event that triggers the function:

mouse.Button1Down:Connect(function()
    if  IsPlaying == false then


        IsPlaying=true
        dead = false
        print("game started!")

        ---------------------------------------------------------------------------
        --Hide the text Uis
        ScreenGUI.Enabled = false

        --Enable physics
        Character.HumanoidRootPart.Anchored = false
        ----------------------------------------------------------------------------------

        MakePillar()
        ---------------------------------------------------------------------------------------

    end
end)

for some reasons SOMETIMES (not always) my function get trigger multiple times at once, can anyone explain?

You can ask me any questions about the local script, i will try to answer them

1 answer

Log in to vote
0
Answered by 2 years ago

you should add wait(1) i think that you are pressing it twice




mouse.Button1Down:Connect(function() wait(1) if IsPlaying == false then IsPlaying=true dead = false print("game started!") --------------------------------------------------------------------------- --Hide the text Uis ScreenGUI.Enabled = false --Enable physics Character.HumanoidRootPart.Anchored = false ---------------------------------------------------------------------------------- MakePillar() --------------------------------------------------------------------------------------- end end)
0
I'm sorry but this didn't fix the problem, plus if i was pressing twice then i think the "game started" should print twice too daokhiethy 25 — 2y
0
use script analyser then Mel_pro1 5 — 2y
Ad

Answer this question