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

How do I get GUIs to not glitch out when tweened by player pressing a key?

Asked by 6 years ago

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)

1 answer

Log in to vote
0
Answered by
ax_gold 360 Moderation Voter
6 years ago
Edited 6 years ago

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

TweenInfo

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)
0
Yeah, I've got the tweening part done, but if the player presses the key before the tween finishes it glitches out. TairaAkiko 26 — 6y
0
The thing is, as seen in your script, you're using :TweenPosition instead of the TweenService method I suggested above. ax_gold 360 — 6y
Ad

Answer this question