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

How do I keybind a textbutton in a Billboard Gui?

Asked by 5 years ago
Edited 5 years ago

I'm currently creating a NPC that has a Billboard Gui located inside of the head and I have put a text button inside of the Billboard Gui. My goal is to make it so that once you are in a certain distance of the dummy, the Gui pops up and you can press Q to place the camera to a camera part. Then it activates another gui meant for chatting with the NPC. So far, I've made it so that the Billboard Gui pops up in a certain range, but I can't seem to figure out how to make the button clickable, much less keybind it to Q. The name of the camera part is MasterCamera. This is my code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local cam = game.Workspace.CurrentCamera

mouse.KeyDown:connect(function(key)
    if key:lower() == "q" then
        print("keyed")
        cam.CameraSubject = game.Workspace.MasterCamera
        cam.CameraType = "Scriptable"
        while wait() do
            cam.CFrame = game.Workspace.MasterCamera.CFrame
        end
    end
end)

I'm stuck on how to get it so it is in a certain range. Please help me, any responses are appreciated!

0
please use the codeblock option to make your code easier to read. RetroGalacticGamer 331 — 5y
0
The script btw is in the StarterGui, one of the only places it will actually work, even though it's broken. SilverArgente 10 — 5y
0
also keydown is deprecated use user input service RetroGalacticGamer 331 — 5y
0
can I contact you in discord? I would like to help you but cant because I dont exactly know how due to lack of knowledge about the problem RetroGalacticGamer 331 — 5y
View all comments (4 more)
0
ok RetroGalacticGamer 331 — 5y
0
sure, you can contact me in discord my discord is silver#0562 SilverArgente 10 — 5y
0
oh nice RetroGalacticGamer 331 — 5y
0
lemme see RetroGalacticGamer 331 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Ok, so first and foremost, KeyDown is deprecated, you need to use UIS (UserInputService)

Inside a LocalScript somewhere under StarterGui

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()

repeat wait() until workspace:FindFirstChild(player.Name) ~= nil

local npc = workspace.NPCs.TheMaster
local gui = npc.Head.BillboardGui

game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Q and gui.Enabled == true then
        camera.CameraSubject = workspace.MasterCamera
        camera.CFrame = workspace.MasterCamera.CFrame
            camera.CameraType = "Scriptable"
        camera.FieldOfView = 70
    end
end)

gui.Header.Activated:Connect(function()
    print("Set-Up Event")
end)

while true do
    local distance = (player.Character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).magnitude
    if distance <= 25 then
        gui.Enabled = true
    else
        gui.Enabled = false
    end
    wait()
end
0
why do you have a repeat until loop when you could just use waitforchild theking48989987 2147 — 5y
0
It worked! Thanks so much! SilverArgente 10 — 5y
Ad
Log in to vote
-3
Answered by 5 years ago

I am helping you with your problem in team create and using discord. No one downvote answer because I am helping him in team create.

0
What was the need to post it as an answer then? Ziffixture 6913 — 5y
0
uh RetroGalacticGamer 331 — 5y
0
I helped him out and you guys are downvoting RetroGalacticGamer 331 — 5y
0
how rude RetroGalacticGamer 331 — 5y

Answer this question