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

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

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

✓ Accepted answer

Use UserInputService.

Here's an example.


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.

1 comment

0

Thank you, Senpai!

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