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!
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
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.