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

It runs, but twice?

Asked by
sigve10 94
8 years ago

I have made a script for a soda dispenser, but for some strange reason: when the button is clicked, it runs the onCola2 twice!?

Is this because of something in the name, as the other onCola is perfectly fine and does not run more than once when the button is pressed. I copied the onCola2 script from the onCola script, and changed the name, as they are in the same script to avoid spending way too much time making connections between many scripts (dispense boolean). Anyone who can help me?

dispensing = false

cola = script.Parent.b1.Handle
colascript = script.Parent.b1.ApertureColaScript
function makecola()
    dispensing = true
    cola.Transparency = 0
    for i=150,300 do
        cola.CFrame = CFrame.new(6.765, cola.Position.Y + 0.01, 8.622)
        wait()
    end
end

function onCola (player)
    if dispensing == false then
    if not player.Backpack:FindFirstChild("Aperture Cola") then
    makecola ()
    wait(1)
    cola.Transparency = 1
    cola.CFrame = CFrame.new(6.765, 3, 8.622)
    local colanew = cola:Clone()
    local colatool = Instance.new("Tool",player.Backpack)
    local scriptnew = colascript:Clone()
    colatool.Name = "Aperture Cola"
    scriptnew.Parent = colatool
    colanew.Parent = colatool
    colanew.Transparency = 0
    wait(1)
    dispensing = false
    end
    end
end

cola2 = script.Parent.b2.Handle
colascript2 = script.Parent.b2.RepulsionSodaScript
function makecola2()
    dispensing = true
    cola2.Transparency = 0
    for i=150,300 do
        cola2.CFrame = CFrame.new(6.765, cola2.Position.Y + 0.01, 8.622)
        wait()
    end
end

function onCola2 (player)
    if dispensing == false then
    if not player.Backpack:FindFirstChild("Repulsion Soda") then
    makecola2 ()
    wait(1)
    cola2.Transparency = 1
    cola2.CFrame = CFrame.new(6.765, 3, 8.622)
    local colanew = cola2:Clone()
    local colatool = Instance.new("Tool",player.Backpack)
    local scriptnew = colascript2:Clone()
    colatool.Name = "Repulsion Soda"
    scriptnew.Parent = colatool
    colanew.Parent = colatool
    colanew.Transparency = 0
    wait(1)
    dispensing = false
    end
    end
end

script.Parent.b2.b2.ClickDetector.MouseClick:connect(onCola2)
script.Parent.b1.b1.ClickDetector.MouseClick:connect(onCola)
0
you put "if dispensing == false then lucas4114 607 — 8y
0
but didn't put dispensing = true after it lucas4114 607 — 8y
0
I have it above in the function makecola2 sigve10 94 — 8y

1 answer

Log in to vote
0
Answered by
sigve10 94
8 years ago

NVM I fixed it. Remember me saying: I put it all in one script to avoid making connections between scripts? Well, I had forgotten to take away the earlier script. But I guess this answered the question anyways.

Ad

Answer this question