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

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

Asked by 4 years ago
Edited 4 years ago

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)

0
Could u fix your code block i cant read it well >_> RealTinCan 217 — 4y
0
I can't seem to fix it, sorry. ROBLOX_sammy048 28 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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
0
Thank You! ROBLOX_sammy048 28 — 4y
Ad

Answer this question