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)
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.
Two things that should be done is
change the reference to the startergui to the playergui
Use userinputservice (InputBegin) as opposed to keydown.
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)
Hopefully this helped!
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)