What do you want to achieve?
I’d like a BillboardGui to appear over an NPC’s (not the players) head when they’re touching an object & then disappear when they’re not touching the object anymore.
What solutions have you tried so far?
I’ve read a few topics on the DevForum about BillboardGui but I haven’t been able to find a topic that was specific to what I’m trying to achieve.
I’ve inserted IntValues named “Num” into each NPC to determine which BillboardGui appears over their head.
Here’s my Explorer setup & the script within the part:
I also apologize if my code is terribly terribly wrong… I’ve just started to try to teach myself how to script and it’s been long/challenging in the beginning.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local NPC = game.Workspace.NPC(hit.Parent)
if NPC then
local Num = NPC.Num.Value
if Num == 1 then
NPC.Head["BillboardGui1"].Enabled = true
elseif Num == 2 then
NPC.Head["BillboardGui2"].Enabled = true
elseif Num == 3 then
NPC.Head["BillboardGui3"].Enabled = true
elseif Num == 4 then
NPC.Head["BillboardGui4"].Enabled = true
end
script.Parent.TouchEnded:Connect(function(hit2)
if hit == hit2 then
NPC.Head["BillboardGui1"].Enabled = false
NPC.Head["BillboardGui2"].Enabled = false
NPC.Head["BillboardGui3"].Enabled = false
NPC.Head["BillboardGui4"].Enabled = false
end
end)
end
end
end)
My script is not working as needed—I forgot to mention that so thank you for asking!
I’ve placed the NPC so that it would be touching the part but the GUI won’t appear. I’m not sure what the specific issue is… perhaps it’s a lot of things I’m not doing right.
I’ve also tried putting the GUI into the NPC’s head; however, it also won’t appear when touching the part either.
Also, how would I change the Default StudOffset in the script? I’m not sure where to put it within my script… again, I’m a newbie
I see what you mean! In order to position the GUI correctly. However, my primary issue is that my script isn’t working the way it’s supposed to (I do appreciate the pointers though!)
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if Hit.Parent.Name == "NPC" then
local NPC = Hit.Parent
local Int = NPC.Num.Value
NPC.Head:FindFirstChild("BillboardGui"..Int).Enabled = true
NPC.Head:FindFirstChild("BillboardGui"..Int).StudsOffset = Vector3.new(0, 1, 0)
script.Parent.TouchEnded:Connect(function(Hit2)
if Hit == Hit2 then
for _, GUIs in pairs(NPC.Head:GetChildren()) do
if GUIs:IsA("BillboardGui") then
GUIs.Enabled = false
end
end
end
end)
end
end
end)
It’s better to use something like delay(delay, function) instead of
script.Parent.TouchEnded:Connect(function(hit2)
if hit == hit2 then
NPC.Head["BillboardGui1"].Enabled = false
NPC.Head["BillboardGui2"].Enabled = false
NPC.Head["BillboardGui3"].Enabled = false
NPC.Head["BillboardGui4"].Enabled = false
end
end)
This is where I put the script.
I currently have Num within the NPC model… should I put Num into the Head of the model instead?
I also put the BillboardGUI into the NPC’s head.
Here’s the script:
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if Hit.Parent.Name == "NPC" then
local NPC = Hit
local Int = NPC.Num.Value
NPC.Head:FindFirstChild("BillboardGui"..Int).Enabled = true
NPC.Head:FindFirstChild("BillboardGui"..Int).StudsOffset = Vector3.new(0, 1, 0)
script.Parent.TouchEnded:Connect(function(Hit2)
if Hit == Hit2 then
for _, GUIs in pairs(NPC.Head:GetChildren()) do
if GUIs:IsA("BillboardGui") then
GUIs.Enabled = false
end
end
end
end)
end
end
end)
I initially included Num in order to have a specific GUI appear but if the GUI is parented to the NPC’s head then I don’t think I need to include the Num IntValue?