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

How do I keybind a textbutton in a Billboard Gui?

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!

8 comments

0

please use the codeblock option to make your code easier to read.

0

The script btw is in the StarterGui, one of the only places it will actually work, even though it's broken.

0

also keydown is deprecated use user input service

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

0

ok

0

sure, you can contact me in discord my discord is silver#0562

0

oh nice

0

lemme see

2 answers

✓ Accepted answer

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

2 comments

0

why do you have a repeat until loop when you could just use waitforchild

0

It worked! Thanks so much!

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.

4 comments

0

What was the need to post it as an answer then?

0

uh

0

I helped him out and you guys are downvoting

0

how rude

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