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

Why my gui isn't opening when I click the key?

Asked by 5 years ago

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)

1 answer

Log in to vote
0
Answered by
Y_VRN 246 Moderation Voter
5 years ago

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.

Ad

Answer this question