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

Press Key To Open GUI [KeyDown] Isn't working?

I'm trying to create a shop GUI for computer player's and since the games in first person a button that you would normally use can't be clicked (unless you are on mobile.) So I decided to use a KeyDown function so every time the player hits "q" the Frame from the GUI will appear along with a smooth animation.

Unfortunately, when the player hits "q" It comes on to the player's screen but only stays there even after you press "q" for it to close. I'm only fairly new to scripting so It's probably some minor error.

----------SCRIPT----------

local toggle = false local frame = script.Parent.Parent:WaitForChild('SHOP').Frame

Player = game.Players.LocalPlayer Mouse = Player:GetMouse() gui = script.Parent frame = gui.Frame

function PressS(key) -- Starts the function if(key == "s")then

frame:TweenPosition(UDim2.new(0.5,-250,0.5,-200),'Out', 'Bounce', 1) -- Tween's up onto players screen
toggle = true

frame:TweenPosition(UDim2.new(0.5,-250,1.7,-200),'Out', 'Bounce', 1) -- Tween's off the players screen
toggle = false

end			

end

Mouse.KeyDown:connect(PressS)

2 comments

0

Could u fix your code block i cant read it well >_>

0

I can't seem to fix it, sorry.

1 answer

✓ Accepted answer

You're missing the toggle check, do something like this:

frame:TweenPosition(UDim2.new(0.5,-250,toggle and 1.7 or .5,-200),'Out', 'Bounce', 1)
toggle = not toggle

1 comment

0

Thank You!

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