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

KeyPress function to open shop not working... Where is my error?

Asked by 3 years ago

So I am practicing my scripting because I just learned Tweening. I tried to make an Inventory script where you press the letter "e" on your keyboard and the GUI comes down to the middle where you can see it but when I press "e" on my keyboard, the GUI won't show up. The output supposedly doesn't say that there is an error... Did I make any mistake in my script? (Down Below)

Script:

player = game.Players.LocalPlayer

if player:GetMouse().KeyDown == "e" then

    -- High Position of Frame: {0.068, 0},{-0.781, 0}
    -- Middle Position of Inventory: {0.068, 0},{0.077, 0}

    Inventory = script.Parent.Inventory 
    Inventory.Visible = true
    Inventory:TweenPosition{

        UDim2(0.068, 0, 0.077, 0),
        Enum.EasingDirection.Out,
        Enum.EasingStyle.Quad,
        0.5,
        false
    }
end

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Mouse has been superseded by UserInputService and ContextActionService. Always refer to API reference pages to keep up to date with things.

local userInputService = game:GetService("UserInputService")
local Inventory = script.Parent.Inventory

userInputService.InputBegan:Connect(function(input)
    if input.KeyCode = Enum.KeyCode.E then
        Inventory.Visible = true
        Inventory:TweenPosition{
            UDim2.new(0.068, 0, 0.077, 0), --your original script would've worked, all you were missing was .new after UDim2
            Enum.EasingDirection.Out,
            Enum.EasingStyle.Quad,
            0.5,
            false
        }
    end
end)
0
Wow! Thank you so much! FilipinoWrld 22 — 3y
Ad

Answer this question