Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Help Needed With Keybind Gui Tweening?

Asked by 15 days ago

I don't understand what is wrong with this. Nothing comes up in the output when i press the keybind. Help?

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local yeet = game.StarterGui.ScreenGui.background.barup

mouse.KeyDown:Connect(function(key)
    if key == "e" then
        yeet:TweenPosition(UDim2.new(0, 64,0, 333), 'Out', 'Bounce', 1)
    end
end)

2 answers

Log in to vote
0
Answered by 15 days ago
Edited 15 days ago

problems


There are two core problems with this. Those being that KeyDown is deprecated, and that you are using StarterGui, rather than the PlayerGui.

The contents of the Starter Gui are cloned into each player's PlayerGui when they join, so modifying the startergui has no effect on the local player.


Fixes


Two things that should be done is

  • change the reference to the startergui to the playergui

  • Use userinputservice (InputBegin) as opposed to keydown.


Fixed Script:


The fixed script should look like something on the lines of this:

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local yeet = plr.PlayerGui:WaitForChild("ScreenGui").background.barup

UIS.InputBegin:Connect(function(input,gpe)
    if input.KeyCode == Enum.KeyCode.E then
        yeet:TweenPosition(UDim2.new(0,64,0,333), 'Out', 'Bounce', 1)
    end
end)

Other Notes


  • Using KeyDown isn't inherently wrong, but as KeyDown is deprecated, it is considered bad practise to do so.

Hopefully this helped!

0
no this will run as long as the key e is down and thats not what this user wants Gameplayer365247v2 449 — 15d
0
Thanks! Shoohtin 4 — 14d
Ad
Log in to vote
0
Answered by 15 days ago
Edited 15 days ago

the following code is the same as the other guy's code but it will only run once and not continuously

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local yeet = plr.PlayerGui:WaitForChild("ScreenGui").background.barup

if UIS:IskeyDown(Enum.KeyCode.E) then
        yeet:TweenPosition(UDim2.new(0,64,0,333), 'Out', 'Bounce', 1)
    end
end)
0
that also wont work , it would only run once when the local script is cloned into the player gui theking48989987 1808 — 15d
0
which , i dont think anyone will be holding the e key as they join a game theking48989987 1808 — 15d
0
also, how do you know what the user wants, the question and the title are very vague theking48989987 1808 — 15d

Answer this question