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

Issues with KeyDown?

Asked by 9 years ago

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

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
9 years ago

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!

0
Thanks Europe! "local key = key:lower() wasn't necessary but you helped a bunch! Thanks. sidekick83 80 — 9y
0
pls accept the answer woodengop 1134 — 9y
Ad
Log in to vote
0
Answered by
yumtaste 476 Moderation Voter
9 years ago

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.

Answer this question