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

Help Needed With Keybind Gui Tweening?

Asked by 4 years 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 4 years ago
Edited 4 years 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 1055 — 4y
0
Thanks! Shoohtin 4 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years 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 2147 — 4y
0
which , i dont think anyone will be holding the e key as they join a game theking48989987 2147 — 4y
0
also, how do you know what the user wants, the question and the title are very vague theking48989987 2147 — 4y

Answer this question