With this script I want to open/close my gui with an animation when I press *. I'm learning lua and I'm not very good so maybe someone can fix my script and explain me why isn't working.
This is my script:
wait() local frame = script.Parent.Parent.Parent.Parent.Parent:WaitForChild('MODmenu').Frame local toggle = false local Player = game.Players.LocalPlayer --TODO: get service local Mouse = Player:GetMouse() local k = script.Parent.Parent.Parent.Key.Value local key = string.lower(k) Mouse.KeyDown:connect(function(Key) if (Key==key)then if toggle == false then frame:TweenPosition(UDim2.new(0,0,0,0), 'Out', 'Bounce', 1) script.Parent.Text = "* to close" toggle = true else frame:TweenPosition(UDim2.new(0,-500,0,0), 'Out', 'Bounce', 1) script.Parent.Text = "* to open" toggle = false end end end)
(note: they key is in a value)
It's probably easier to use UserInputService instead. Just about the value in the script, you can just assign the variable a value directly in the script, like so: variable = "value"
. Applies to all value types.
Anyways: I changed (probably) a lot in your code, so this should work:
wait() local frame = script.Parent.Parent.Parent.Parent.Parent.MODmenu.Frame -- If the "MODmenu" is not yet in the UI, replace with WaitForChild(), like the previous -- sample you have shown. If not, keep it the same. local toggle = false local Player = game.Players.LocalPlayer local UIP = game:GetService("UserInputService") local k = Enum.KeyCode.KeypadMultiply -- Trying to use Enum.KeyCode.Asterisk doesn't seem to work. KeypadMultiply should do the trick. UIP.InputBegan:Connect(function(Key) if Key.KeyCode == k then if toggle == false then frame:TweenPosition(UDim2.new(0,0,0,0), 'Out', 'Bounce', 1) script.Parent.Text = "* to close" toggle = true else frame:TweenPosition(UDim2.new(0,-500,0,0), 'Out', 'Bounce', 1) script.Parent.Text = "* to open" toggle = false end end end)
Place this code inside a LocalScript instead of a normal Script. This is due to ROBLOX's kinda recent update I think.