TweeningGui when someone clicked a keyboard button

I’m trying to tween a GUI when a player a keyboard button like “K” etc
I’ve search youtube and google but I couldn’t find what I want

here’s the script:

local player = game.Players.LocalPlayer

local AdminPanel = player:WaitForChild("PlayerGui"):WaitForChild("AdminPanel")

local List = player:WaitForChild("PlayerGui"):WaitForChild("PlayerListGui")

local UserInputService = game:GetService("UserInputService")

function tween()
    AdminPanel:TweenPosition(UDim2.new(0.246, 0,0.093, 0)"Out","Linenear")
end

UserInputService.InputBegan:Connect(function(input, IsTyping)
    if not IsTyping then
        if input.KeyCode == Enum.KeyCode.L then
            tween()

and there’s an error:
Players.dirtandra123.PlayerGui.LocalScript:10: attempt to call a UDim2 value

any solutions?

Correction:

AdminPanel:TweenPosition(UDim2.new(0.246, 0,0.093, 0), "Out", "Linear")

You forgot the comma.

2 Likes

it didn’t work and there’s a new error, the previous error has disappeared and a new error has appeared
TweenPosition is not a valid member of ScreenGui “Players.dirtandra123.PlayerGui.AdminPanel”

seems like you’re trying to tween the ScreenGui instead of a GUI component.
create a frame, put everything you have in that GUI there and then tween that frame.

local player = game.Players.LocalPlayer

local AdminPanel = player:WaitForChild("PlayerGui"):WaitForChild("AdminPanel")

local List = player:WaitForChild("PlayerGui"):WaitForChild("PlayerListGui")

local UserInputService = game:GetService("UserInputService")

function tween()
    AdminPanel:TweenPosition(UDim2.new(0.246, 0,0.093, 0), "Out", "Linear", 1, false)
end

UserInputService.InputBegan:Connect(function(input, IsTyping)
    if not IsTyping then
        if input.KeyCode == Enum.KeyCode.L then
            tween()

You forgot the time and override type
, "Out", "Linear", 1, false

GuiObject:TweenPosition (roblox.com)

But im not sure if you need it.

1 Like

oh yeah I forgot to do that, and there’s a new error that appear
Unable to cast string to token

May I ask in wich line the error is?

it still gives the same error like this

yes, of course, its on line 10

Alright, I found the issue.
You typed Linenear wrong. It have to be Linear. :laughing:

So it have to look like this:

AdminPanel:TweenPosition(UDim2.new(0.246, 0,0.093, 0), "Out","Linear")
1 Like

replace that line with this:
AdminPanel:TweenPosition(UDim2.new(0.246, 0,0.093, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear)

2 Likes
local player = game.Players.LocalPlayer

local AdminPanel = player:WaitForChild("PlayerGui"):WaitForChild("AdminPanel")

local List = player:WaitForChild("PlayerGui"):WaitForChild("PlayerListGui")

local UserInputService = game:GetService("UserInputService")

function tween()
    AdminPanel:TweenPosition(UDim2.new(0.246, 0,0.093, 0),"Out","Linear",false,0.2)
end

UserInputService.InputBegan:Connect(function(input, IsTyping)
    if not IsTyping then
        if input.KeyCode == Enum.KeyCode.L then
            tween()
        end
    end
end)

try this in a local script

2 Likes

You are trying to tween a ScreenGui, you can tween only Frames, Labels, etc.

1 Like

I know I’ve updated the script into:

AdminPanel:WaitForChild("Frame"):TweenPosition(UDim2.new(0.246, 0,0.093, 0),"Out","Linear",false,0.2)

Then please mark a reply as solution. So they know its fixed. :slight_smile:

1 Like

thanks to all who have tried to help me i appreciate it :smile:

Ok now do this:

local player = game.Players.LocalPlayer

local AdminPanel:WaitForChild("Frame"):TweenPosition(UDim2.new(0.246, 0,0.093, 0),"Out","Linear",false,0.2)

local UserInputService = game:GetService("UserInputService")

function tween()
    AdminPanel:TweenPosition(Udim2.new(0.246, 0, 0.093, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 1)
end

UserInputService.InputBegan:Connect(function(keycode, IsTyping)
    if not IsTyping then
        if keycode.KeyCode == Enum.KeyCode.L then
            tween()
         end
     end
end)