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

Pressing the F key and no GUI appears?

Hello all, recently I developed a script that when a players mouse goes over a NPC a gui appears using tweening ect. The gui then displays "Press F to open the store". This has all been scripted so when the "f" key is pressed the visibility of the store gui is set to true. And goes as following . However upon pressing the F key nothing happens, could I please have some help?

local uis = game:GetService("UserInputService")
local raus,vaus
local StoreGui = game.StarterGui.Store.StoreGui
local settings = {
	key = "e"
}


local player = game.Players.LocalPlayer
local mouse  = player:GetMouse()
while true do 
	if mouse.Target ~= nil and mouse.Target.Parent:FindFirstChild("HumanoidRootPart") and not game.Players:FindFirstChild(mouse.Target.Parent.Name) then
		print("Works")
		if mouse.Target.Position.X - player.Character.HumanoidRootPart.Position.X < 10  and  mouse.Target.Position.Z - player.Character.HumanoidRootPart.Position.Z < 10 then
			print("works2")
		script.Parent.Frame:TweenPosition(UDim2.new(0.12 , 0 ,0.1 , 0) , "Out" , "Linear" , 0.5)
		else
			script.Parent.Frame:TweenPosition(UDim2.new(0.12 , 0 ,1 , 0) , "In" , "Linear" , 0.5)
		end
	else
		script.Parent.Frame:TweenPosition(UDim2.new(0.12 , 0 ,1 , 0) , "In" , "Linear" , 0.5)
	end
	
	wait()
end



local input = uis.InputBegan.connect(function(key,gpe)
	if key.KeyCode == Enum.KeyCode[string.upper(settings.key)] and vaus ~= true then
		StoreGui.visible = true
		
	end
end)

5 comments

0

first of all its E

0

yes the key is "E" not "e"

0

Plus, the question title doesn't fit the key you're trying to press

0

You are trying to press "F" and not "E", correct?

0

Yes it’s meant to be E, my mistake. Also in the script if you looked at line 30 it sets it to upper case.

1 answer

local uis = game:GetService("UserInputService")
local raus,vaus
local StoreGui = game.StarterGui.Store.StoreGui
local settings = {
    key = "F"
}


local player = game.Players.LocalPlayer
local mouse  = player:GetMouse()
while true do 
    if mouse.Target ~= nil and mouse.Target.Parent:FindFirstChild("HumanoidRootPart") and not game.Players:FindFirstChild(mouse.Target.Parent.Name) then
        print("Works")
        if mouse.Target.Position.X - player.Character.HumanoidRootPart.Position.X < 10  and  mouse.Target.Position.Z - player.Character.HumanoidRootPart.Position.Z < 10 then
            print("works2")
        script.Parent.Frame:TweenPosition(UDim2.new(0.12 , 0 ,0.1 , 0) , "Out" , "Linear" , 0.5)
        else
            script.Parent.Frame:TweenPosition(UDim2.new(0.12 , 0 ,1 , 0) , "In" , "Linear" , 0.5)
        end
    else
        script.Parent.Frame:TweenPosition(UDim2.new(0.12 , 0 ,1 , 0) , "In" , "Linear" , 0.5)
    end

    wait()
end



local input = uis.InputBegan.connect(function(key,gpe)
    if key.KeyCode == Enum.KeyCode[string.upper(settings.key)] and vaus ~= true then
        StoreGui.Visible = true

    end
end)

You set it to the wrong key. The key that is pressed must always be a capital letter (if the key is a letter).

Also, the visible property is deprecated. Use its capitalized counterpart, Visible.

5 comments

0

He sets the key to it's upper case on line 30 anyways.

0

Thanks, but even after testing and stuff it still doesn't seem to work.

0

oh i see the problem

0

change ".connect" to ":Connect" on line 29

0

Hey, it still doesn't seem to work. If you have disc add me ChickenSalt#0386 and I can add you to team create so you can hopefully point out the problem.

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