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)

3 comments
you put "if dispensing == false then
but didn't put dispensing = true after it
I have it above in the function makecola2