Trying to make a BillboardGUI Local to the player

Hey forum, I have finally gotten my NPC chat system… good? And I now need to make it so that it is local to the player. The problem is, is that this is a BillboardGUI which means no LocalScript runs in it! Heres the code, and are there any solutions?:

local chat = script.Parent
local child = script.Parent.Text
-- local button = script.Parent.ClickButton (IGNORE, FOR LATER)

local touching = false

chat.Visible = false
child.Visible = false

local function onTouch(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player and not touching then
		chat.Visible = true

		script.Parent:TweenSize(UDim2.new(0, 252,0, 50), "Out", "Elastic", 2) 

		child.Visible = true
		touching = true
	end
end

local function onTouchEnded()
	if touching then
		chat.Visible = false
		child.Visible = false
		touching = false
		chat:TweenSize(false)
	end
end

game.Workspace.Characters.Cardinal.Activator.Touched:Connect(onTouch)
game.Workspace.Characters.Cardinal.Activator.TouchEnded:Connect(onTouchEnded)

Anything that you want to happen just for a local player needs to happen on the client. Fire a RemoteEvent to the client in your script above and handle in on the client side with the changes you want to occur there.

Ah, so what you’re saying (to simplify) is the player touching the part might be server and fire to a LocalScript and that will make the BillboardGUI happen.

The BillboardGui is being created as a child of the Workspace, and not as a child of the Adornee object (in this case, the Activator part) that you want it to follow.

You can modify your code to make the BillboardGui local to the player, using the Adornee property.

Here is a simple example.

local player = game:GetService("Players").LocalPlayer
local head = player.Character.Head


local gui = Instance.new("BillboardGui")
gui.Adornee = head
gui.Parent = head

When you attach a BillboardGui to a player’s Head and set the Adornee property to that object, the BillboardGui will only be visible to the player whose Head is being used as the Adornee. Other players will not be able to see the BillboardGui because it is positioned relative to the local player’s camera view of the Head object.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.