I've been testing out the KeyDown event, and I've been successful with changing my player's walkspeed with it, and other basic things.
Now, I'm trying to make the Key, "q," tween my Frame's Position to the center of the screen. I've added "print("tweened") after the TweenPosition function. To my surprise the "tweened" came out in the output but the Frame hadn't been Tweened.
Here's the code:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local frame = game.StarterGui.gui.Frame mouse.KeyDown:connect(function(key) if key == "q" then frame:TweenPosition(UDim2.new(.5, -150, .5, -100), "Out", "Back", .5, true) print("tweened") end end)
Any help with this would be much appreciated, thanks!
First I see a Problem in line 6, Let me show you how You would do it
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local frame = player:WaitForChild("PlayerGui"):WaitForChild("gui"):WaitForChild("frame") mouse.KeyDown:connect(function(key) local key=key:lower() if key=="q" then frame:TweenPosition(UDim2.new(.5, -150, .5, -100), "Out", "Back", .5, true) print("tweened") end end)
First you Would have to add a(n)
local key=key:lower() it activates whenever you Click q
Hope This Helped!
You're tweening something in the StarterGui, which only stores GUIs that are going to be given to players. Try making "frame" a hierarchy relative to the script, such as script.Parent.Parent
.