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 4 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:

01player = game.Players.LocalPlayer
02 
03if player:GetMouse().KeyDown == "e" then
04 
05    -- High Position of Frame: {0.068, 0},{-0.781, 0}
06    -- Middle Position of Inventory: {0.068, 0},{0.077, 0}
07 
08    Inventory = script.Parent.Inventory
09    Inventory.Visible = true
10    Inventory:TweenPosition{
11 
12        UDim2(0.068, 0, 0.077, 0),
13        Enum.EasingDirection.Out,
14        Enum.EasingStyle.Quad,
15        0.5,
16        false
17    }
18end

1 answer

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

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

01local userInputService = game:GetService("UserInputService")
02local Inventory = script.Parent.Inventory
03 
04userInputService.InputBegan:Connect(function(input)
05    if input.KeyCode = Enum.KeyCode.E then
06        Inventory.Visible = true
07        Inventory:TweenPosition{
08            UDim2.new(0.068, 0, 0.077, 0), --your original script would've worked, all you were missing was .new after UDim2
09            Enum.EasingDirection.Out,
10            Enum.EasingStyle.Quad,
11            0.5,
12            false
13        }
14    end
15end)
0
Wow! Thank you so much! FilipinoWrld 22 — 4y
Ad

Answer this question