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

How can I make it so a key opens a GUI? Keeps giving me a nil value

Asked by 5 years ago

local frame = script.Parent.Parent:WaitForChild("Frame")

local open = script.Parent.Parent.Open

Player = game.Players.LocalPlayer

Mouse = Player:GetMouse()

function PressI(key)

if (key == "x") then

if open.Value == false then

frame:TweenPosition(UDim2.new(0.243,0,0.127,0),"Out","Quint",1,true) -- Position of your frame when its opened

open.Value = true

elseif open.Value == true then

frame:TweenPosition(UDim2.new(0.243,0,-0.127,-401),"Out","Quint",1,true) -- Position of your frame when its closed

open.Value = false

end

end

end

Mouse.KeyDown:connect(PressI)

1 answer

Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
5 years ago
Edited 5 years ago

Use UserInputService.

Here's an example. ```lua

local Keycodes = Enum.KeyCode --For easier reference. local Up = true; game:GetService('UserInputService').InputBegan:Connect(function(Key, Process) if (Process) then return end --If the player is in the menu, or a frame with Modal is present, then don't continue. Key = Key.KeyCode --Reassign key to it's keycode.

if (Key == Keycodes.E) then
    if (not Up) then
        script.Parent:WaitForChild('Frame'):TweenPosition(UDim2.new(0,0,-1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 1, true) --Tween a frame upwards
        Up = true
    else
        script.Parent:WaitForChild('Frame'):TweenPosition(UDim2.new(0,0,0,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 1, true) --Tween a frame back down
        Up = false
    end
end

end) ``` If something's giving you a nil value, it's most likely the BoolValue. Try using WaitForChild on the "open" variable.

0
Thank you, Senpai! XxBORNTOHACKxX 3 — 5y
Ad

Answer this question