I’m making a regen button for my roller coaster cart as every now and then it tends to lag and roll back. I made this script, and it runs very good and very smooth as intended. But when I click the button for the second,third,forth, etc. time it just doesn’t work. It will not repeat and I have no idea why.
local cartM = script.Parent.Parent.Parent
local delaytime = .2
script.Parent.cd.MouseClick:Connect(function()
script.Parent.Parent.Parent.cart:Destroy()
wait(delaytime)
local cart =game.ServerStorage.Regenvehicles["MEG cart"]:Clone()
cart.Parent = cartM
end)
The problem may be since the function is called at the beginning with .MouseClick:Connect(function() It may only recognize this once. Try replacing the function with a while true do loop
local cartM = script.Parent.Parent.Parent
local delaytime = .2
while true do
if script.Parent.cd.MouseButton1Click then
script.Parent.Parent.Parent.cart:Destroy()
wait(delaytime)
local cart = game.ServerStorage.Regenvehicles["MEG cart"]:Clone()
cart.Parent = cartM
end
end
local cartM = script.Parent.Parent.Parent
local delaytime = .2
if script.Parent.cd.MouseClick then
script.Parent.Parent.Parent.cart:Destroy()
wait(delaytime)
local cart = game.ServerStorage.Regenvehicles["MEG cart"]:Clone()
cart.Parent = cartM
end