Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help Needed With Keybind Gui Tweening?

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

✓ Accepted answer

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!

2 comments

0

no this will run as long as the key e is down and thats not what this user wants

0

Thanks!

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)

3 comments

0

that also wont work , it would only run once when the local script is cloned into the player gui

0

which , i dont think anyone will be holding the e key as they join a game

0

also, how do you know what the user wants, the question and the title are very vague

This discussion is preserved as it was. New answers, comments, and votes are closed.