So when you click on the button it tweens a Frame onto the screen and that frame has an X button to close it. The X button also runs a tween to move the frame off of the screen. But if you spam both buttons it will glitch out since both functions are running too many times. I could use a debounce but the problem is they are on two different scripts. Any way I can disable the function without disabling the ENTIRE script?
If you need my code, screenshots, or any other resources just ask me.
Thanks
SCRIPT 1
local PlayerGUI = game.Players.LocalPlayer.PlayerGui
local Stroke = PlayerGUI.OpenEggs.Frame:WaitForChild("Stroke")
local Btn = PlayerGUI.OpenEggs.Frame:WaitForChild("CloseBtn")
local TL = PlayerGUI.OpenEggs.Frame:WaitForChild("CloseBtn"):WaitForChild("TextLabel")
local GUI = PlayerGUI:WaitForChild("OpenEggs")
local TS = game:GetService("TweenService")
local Frame = GUI:WaitForChild("Frame")
local EggDecals = GUI:WaitForChild("EggDecals")
local Egg1 = EggDecals:WaitForChild("Egg1")
local Egg2 = EggDecals:WaitForChild("Egg2")
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Stroke.MouseButton1Down:Connect(function()
TS:Create(Btn, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.08,.099), Position = UDim2.fromScale(.942,-.029)}):Play()
TS:Create(TL, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.159,.185), TextSize = 75, Position = UDim2.fromScale(.495,.5)}):Play()
TS:Create(Stroke, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.092,.115), Position = UDim2.fromScale(.936,-.037)}):Play()
TS:Create(Egg1, TweenInfo.new(.35, Enum.EasingStyle.Exponential, Enum.EasingDirection.In), {Position = UDim2.fromScale(0.69, Egg1.Position.Y.Scale)}):Play()
TS:Create(Egg2, TweenInfo.new(.35, Enum.EasingStyle.Exponential, Enum.EasingDirection.In), {Position = UDim2.fromScale(0.192, Egg2.Position.Y.Scale)}):Play()
wait(.4)
EggDecals.Visible = false
TS:Create(Frame, TweenInfo.new(.4, Enum.EasingStyle.Exponential, Enum.EasingDirection.In), {Position = UDim2.fromScale(.5,2.493)}):Play()
end)
Stroke.MouseButton1Up:Connect(function()
TS:Create(Btn, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.102,0.125), Position = UDim2.fromScale(.932,-.045)}):Play()
TS:Create(TL, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.159,0.185), TextSize = 100, Position = UDim2.fromScale(.495,.5)}):Play()
TS:Create(Stroke, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.115,.151), Position = UDim2.fromScale(.925,-.054)}):Play()
end)
Stroke.MouseEnter:Connect(function()
TS:Create(Btn, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.113,0.14), Position = UDim2.fromScale(.926,-.054)}):Play()
TS:Create(TL, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.159,0.185), TextSize = 100, Position = UDim2.fromScale(.495,.5)}):Play()
TS:Create(Stroke, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.126,.166), Position = UDim2.fromScale(.919,-.062)}):Play()
end)
Stroke.MouseLeave:Connect(function()
TS:Create(Btn, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.102,0.125), Position = UDim2.fromScale(.932,-.045)}):Play()
TS:Create(TL, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.159,0.185), TextSize = 100, Position = UDim2.fromScale(.495,.5)}):Play()
TS:Create(Stroke, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.115,.151), Position = UDim2.fromScale(.925,-.054)}):Play()
end)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Btn.MouseButton1Down:Connect(function()
TS:Create(Btn, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.08,.099), Position = UDim2.fromScale(.942,-.029)}):Play()
TS:Create(TL, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.159,.185), TextSize = 75, Position = UDim2.fromScale(.495,.5)}):Play()
TS:Create(Stroke, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.092,.115), Position = UDim2.fromScale(.936,-.037)}):Play()
TS:Create(Egg1, TweenInfo.new(.35, Enum.EasingStyle.Exponential, Enum.EasingDirection.In), {Position = UDim2.fromScale(0.69, Egg1.Position.Y.Scale)}):Play()
TS:Create(Egg2, TweenInfo.new(.35, Enum.EasingStyle.Exponential, Enum.EasingDirection.In), {Position = UDim2.fromScale(0.192, Egg2.Position.Y.Scale)}):Play()
wait(.4)
EggDecals.Visible = false
TS:Create(Frame, TweenInfo.new(.4, Enum.EasingStyle.Exponential, Enum.EasingDirection.In), {Position = UDim2.fromScale(.5,2.493)}):Play()
end)
Btn.MouseButton1Up:Connect(function()
TS:Create(Btn, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.102,0.125), Position = UDim2.fromScale(.932,-.045)}):Play()
TS:Create(TL, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.159,0.185), TextSize = 100, Position = UDim2.fromScale(.495,.5)}):Play()
TS:Create(Stroke, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.115,.151), Position = UDim2.fromScale(.925,-.054)}):Play()
end)
Btn.MouseEnter:Connect(function()
TS:Create(Btn, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.113,0.14), Position = UDim2.fromScale(.926,-.054)}):Play()
TS:Create(TL, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.159,0.185), TextSize = 100, Position = UDim2.fromScale(.495,.5)}):Play()
TS:Create(Stroke, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.126,.166), Position = UDim2.fromScale(.919,-.062)}):Play()
end)
Btn.MouseLeave:Connect(function()
TS:Create(Btn, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.102,0.125), Position = UDim2.fromScale(.932,-.045)}):Play()
TS:Create(TL, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(0.159,0.185), TextSize = 100, Position = UDim2.fromScale(.495,.5)}):Play()
TS:Create(Stroke, TweenInfo.new(.1, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(.115,.151), Position = UDim2.fromScale(.925,-.054)}):Play()
end)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SCRIPT 2
local Button = game.Players.LocalPlayer.PlayerGui:WaitForChild("Button")
local point = game.Workspace.MainFolder:WaitForChild("Eggs"):WaitForChild("Basic Egg")
local OpenEggs = game.Players.LocalPlayer.PlayerGui:WaitForChild("OpenEggs")
local Frame = game.Players.LocalPlayer.PlayerGui:WaitForChild("OpenEggs"):WaitForChild("Frame")
local EggDecals = game.Players.LocalPlayer.PlayerGui:WaitForChild("OpenEggs"):WaitForChild("EggDecals")
local Egg1 = EggDecals:WaitForChild("Egg1")
local Egg2 = EggDecals:WaitForChild("Egg2")
local tweenService = game:GetService("TweenService")
local RS = game:GetService("RunService")
local TextButton = Button.TextButton
local UIS = game:GetService("UserInputService")
local isPlayerHoldingDownE = false
local debounceToStopSpam_1 = false
local debounceToStopSpam_2 = false
RS.Heartbeat:Connect(function()
local players = game.Players:GetPlayers()
for index, player in pairs(players) do
if player.Character then
local target = player.Character
local distance = (point.Position - target.HumanoidRootPart.Position).Magnitude
local radius = 5
if distance < radius then
Button.Enabled = true
tweenService:Create(Button, TweenInfo.new(.3, Enum.EasingStyle.Exponential), {Size = UDim2.fromScale(4.5,4.5)}):Play()
else
tweenService:Create(Button, TweenInfo.new(.3, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Size = UDim2.fromScale(.6,.6)}):Play()
task.wait(.01)
Button.Enabled = false
end
end
end
end)
game.Players.LocalPlayer.PlayerGui.Button.TextButton.MouseButton1Click:Connect(function()
OpenEggs.Enabled = true
tweenService:Create(Frame, TweenInfo.new(.4, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Position = UDim2.fromScale(.5,.493)}):Play()
wait(.4)
EggDecals.Visible = true
tweenService:Create(Egg1, TweenInfo.new(.35, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Position = UDim2.fromScale(0.805, Egg1.Position.Y.Scale)}):Play()
tweenService:Create(Egg2, TweenInfo.new(.35, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Position = UDim2.fromScale(0.043, Egg2.Position.Y.Scale)}):Play()
end)
-- ANIMATION AND CLICK ^^^^^^^^^
----------------------------------------------------------------------------------------------------------------------------------------------
-- PRESS E VVVVVVVVVV
RS.Heartbeat:Connect(function()
local players = game.Players:GetPlayers()
for index, player in pairs(players) do
if player.Character then
local target = player.Character
local distance = (point.Position - target.HumanoidRootPart.Position).Magnitude
local radius = 5
if isPlayerHoldingDownE then
if debounceToStopSpam_1 == false then
debounceToStopSpam_1 = true
debounceToStopSpam_2 = false
--print("player is holding down E!")
end
if distance < radius then
OpenEggs.Enabled = true
tweenService:Create(Frame, TweenInfo.new(.4, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Position = UDim2.fromScale(.5,.493)}):Play()
wait(.4)
EggDecals.Visible = true
tweenService:Create(Egg1, TweenInfo.new(.35, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Position = UDim2.fromScale(0.805, Egg1.Position.Y.Scale)}):Play()
tweenService:Create(Egg2, TweenInfo.new(.35, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Position = UDim2.fromScale(0.043, Egg2.Position.Y.Scale)}):Play()
else
-- print("not close enough!")
end
else
if debounceToStopSpam_2 == false then
debounceToStopSpam_2 = true
debounceToStopSpam_1 = false
--print("player is NOT holding down E!")
end
end
end
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
isPlayerHoldingDownE = true
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
isPlayerHoldingDownE = false
end
end)
VIDEO