How do I get my gui to not glitch out or disappear when being tweened when a player spams a key instead of waiting for the tween to finish?
-- wait(0.3) -- local PlayerService = game:GetService("Players") local player = game.Players.LocalPlayer.Character local Backpack = game.Players.LocalPlayer.Backpack local hum = player.Humanoid -- local weapon = script.Parent.Weapon local item = script.Parent.Item local clothes = script.Parent["?"] local equiped = script.Parent.Equiped local wepinv = script.Parent["Weapon.Inv"] local iteminv = script.Parent["Item.Inv"] local invtitle = script.Parent["Inv.Title"] local equiptitle = script.Parent["Equipped.Title"] inv = false -- uis = game:GetService("UserInputService") plr = game.Players.LocalPlayer -- uis.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.B and inv == false then weapon:TweenPosition(UDim2.new( 0, 150, 0, 210), 'InOut', 'Sine', 1.5) item:TweenPosition(UDim2.new( 0, 360, 0, 210), 'InOut', 'Sine', 1.5) clothes:TweenPosition(UDim2.new( 0, 570, 0, 210), 'InOut', 'Sine', 1.5) equiped:TweenPosition(UDim2.new( 0, 780, 0, 210), 'InOut', 'Sine', 1.5) wepinv:TweenPosition(UDim2.new( 0, 150, 0, 310), 'InOut', 'Sine', 1.5) iteminv:TweenPosition(UDim2.new( 0, 150, 0, 310), 'InOut', 'Sine', 1.5) invtitle:TweenPosition(UDim2.new( 0, 150, 0, 80), 'InOut', 'Sine', 1.5) equiptitle:TweenPosition(UDim2.new( 0, 780, 0, 80), 'InOut', 'Sine', 1.5) inv = true end end) uis.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.B and inv == true then weapon:TweenPosition(UDim2.new( -1, 150, 0, 210), 'InOut', 'Sine', 1.5) item:TweenPosition(UDim2.new( -1, 360, 0, 210), 'InOut', 'Sine', 1.5) clothes:TweenPosition(UDim2.new( -1, 570, 0, 210), 'InOut', 'Sine', 1.5) equiped:TweenPosition(UDim2.new( -1, 780, 0, 210), 'InOut', 'Sine', 1.5) wepinv:TweenPosition(UDim2.new( -1, 150, 0, 310), 'InOut', 'Sine', 1.5) iteminv:TweenPosition(UDim2.new( -1, 150, 0, 310), 'InOut', 'Sine', 1.5) invtitle:TweenPosition(UDim2.new( -1, 150, 0, 80), 'InOut', 'Sine', 1.5) equiptitle:TweenPosition(UDim2.new( -1, 780, 0, 80), 'InOut', 'Sine', 1.5) inv = false end end)
Use TweenService (game:GetService("TweenService")
.)
It's kind of complicated and hard to explain, so here's some sites you may want to read for info:
TweenService also works with Positions, sizes, pretty much anything that's a number value. and it works with blocks too! Here's an example from one of my scripts:
local tween = game:GetService("TweenService") local info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) arrow.MouseButton1Click:connect(function() if arrow.Text == "<" then arrow.Text = ">" local goal = {["Position"] = UDim2.new(0,-206,0,0)} tween:Create(mframe, info, goal):Play() elseif arrow.Text == ">" then arrow.Text = "<" local goal = {["Position"] = UDim2.new(0,0,0,0)} tween:Create(mframe, info, goal):Play() end end)