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

Issues with KeyDown?

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!

2 answers

✓ Accepted answer

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!

2 comments

0

Thanks Europe! "local key = key:lower() wasn't necessary but you helped a bunch! Thanks.

0

pls accept the answer

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.

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