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

Pressing the F key and no GUI appears?

Asked by 5 years ago
Edited 5 years ago

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)
0
first of all its E Benjamin_pro1000 3 — 5y
0
yes the key is "E" not "e" DeceptiveCaster 3761 — 5y
0
Plus, the question title doesn't fit the key you're trying to press DeceptiveCaster 3761 — 5y
0
You are trying to press "F" and not "E", correct? DeceptiveCaster 3761 — 5y
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. iChaboyy 7 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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.

0
He sets the key to it's upper case on line 30 anyways. xPolarium 1388 — 5y
0
Thanks, but even after testing and stuff it still doesn't seem to work. iChaboyy 7 — 5y
0
oh i see the problem DeceptiveCaster 3761 — 5y
0
change ".connect" to ":Connect" on line 29 DeceptiveCaster 3761 — 5y
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. iChaboyy 7 — 5y
Ad

Answer this question