Problems with billboardgui

Hi all!
My buttons for the billboardgui do not get created 50% of the time for whatever reasons. Any help is appreciated!
Here is the video:

local BillboardGui = PlayerGui:WaitForChild("SellOptions");
BillboardGui.Adornee = SellNPC:WaitForChild("HumanoidRootPart"); --For whatever reason it doesn't work unless I add this
script.UIListLayout.Parent = BillboardGui;
for Number, Text in pairs(SellOptions) do
    
    local Clone = script.Button:Clone();
    Clone.Number.Text = string.format("#%s", Number);
    Clone.TextLabel.Text = string.format("%s", Text);
    Clone.Name = Number;
    
    Clone.Parent = BillboardGui;
    
    local HoverTween = TweenService:Create(
        Clone.TextLabel,
        TweenInfo.new(0.5),
        {
            Position = UDim2.new(0.1,0,0,0);
        }
    );

    local UnhoverTween = TweenService:Create(
        Clone.TextLabel,
        TweenInfo.new(0.25),
        {
            Position = UDim2.new(0.05,0,0,0);
        }
    );
    
    Clone.MouseButton1Click:Connect(function()

        SellFunctions[Number]();
    end);

    Clone.MouseEnter:Connect(function()

        HoverTween:Play();
    end);

    Clone.MouseLeave:Connect(function()

        UnhoverTween:Play();
    end);
end
1 Like

You’re going to have to show us some more context.
The issue doesn’t seem to be in the code snippet you provided.

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local TweenService = game:GetService("TweenService");
local RunService = game:GetService("RunService");
local Players = game:GetService("Players");

local LocalPlayer = Players.LocalPlayer;

local SellBooth = workspace:WaitForChild("SellBooth");
local BuyBooth = workspace:WaitForChild("BuyBooth");

local SellNPC = SellBooth:WaitForChild("Rig");
local BuyNPC = BuyBooth:WaitForChild("Rig");

local NPCNeck = SellNPC:WaitForChild("Head"):WaitForChild("Neck");
local CFrame0 = NPCNeck.C0;

local Modules = ReplicatedStorage:WaitForChild("Modules");

local module = require(Modules:WaitForChild("TextModule"));

local PlayerGui = LocalPlayer:WaitForChild("PlayerGui");
local BillboardGui = PlayerGui:WaitForChild("SellOptions");
BillboardGui.Adornee = SellNPC:WaitForChild("HumanoidRootPart");

local SellDebounce = false;
local BuyDebounce = false;
local SellActive = false;
local Annoyed = 0;

local SellOptions = {
	[1] = '["I want to sell my inventory"]';
	[2] = '["I want to sell this"]';
	[3] = '["How much is this worth?"]';
	[4] = '["Nevermind"]';
}



local function CloseSell()
	
	SellActive = false;
	
	for i = 1, 4, 1 do
		
		BillboardGui[i].Visible = false;
	end;
end;

SellNPC.ProximityPrompt.Triggered:Connect(function(player)
	
	if SellDebounce == true then return; end;
	SellDebounce = true;
	
	if SellActive == true then
		
		Annoyed += 1;
		
		if Annoyed == 3 then
			
			module.AnimateText(
				"<bold><red><shake>Dude...</shake></red></bold>",
				SellNPC.Head.TextBox,
				0.04,
				Enum.Font.Arial,
				"fade diverge",
				1,
				24
			);
		else
			
			module.AnimateText(
				"<bold>Use my righthand menu to choose what you want to do!</bold>",
				SellNPC.Head.TextBox,
				0.04,
				Enum.Font.Arial,
				"fade diverge",
				1,
				24
			);
		end
		
		task.wait(1.5);

		module.ClearText(SellNPC.Head.TextBox, {
			direction = "right",
			duration = 0.3,
			order = "reverse"
		});
		
		SellDebounce = false;
		return;
	end;
	
	
	coroutine.wrap(function()
		
		Annoyed = 0;
		module.AnimateText(
			"<bold>Have anything to <wave><color=#FFFF00>sell</color></wave>?</bold>",
			SellNPC.Head.TextBox,
			0.04,
			Enum.Font.Arial,
			"fade diverge",
			1,
			24
		);
		
		task.wait(3);

		module.ClearText(SellNPC.Head.TextBox, {
			direction = "right",
			duration = 0.3,
			order = "reverse"
		});

		SellDebounce = false;
	end)()
	
	task.wait(0.75)
	
	SellActive = true;
	
	for i = 1, 4, 1 do
		
		BillboardGui[i].Visible = true;
		task.wait(0.15);
	end;
end);


BuyNPC.ProximityPrompt.Triggered:Connect(function(player)

	if BuyDebounce == true then return; end;

	BuyDebounce = true;
	
	coroutine.wrap(function()
		
		module.AnimateText(
			"<bold>Interested in <wave><color=#FFFF00>buying</color></wave> anything?</bold>",
			BuyNPC.Head.TextBox,
			0.04,
			Enum.Font.Arial,
			"fade diverge",
			1,
			24
		);

		task.wait(3);

		module.ClearText(BuyNPC.Head.TextBox, {
			direction = "right",
			duration = 0.3,
			order = "reverse"
		});

		BuyDebounce = false;
	end)();
	
	task.wait(0.75);
	ReplicatedStorage.Events.BuyNPC:FireServer("Part");
end);

script.UIListLayout.Parent = BillboardGui;
local SellFunctions = {
	[1] = function()


	end,
	[2] = function()


	end,
	[3] = function()


	end,
	[4] = function()

		CloseSell();
	end,
}

for Number, Text in pairs(SellOptions) do
	
	local Clone = script.Button:Clone();
	Clone.Number.Text = string.format("#%s", Number);
	Clone.TextLabel.Text = string.format("%s", Text);
	Clone.Name = Number;
	
	Clone.Parent = BillboardGui;
	
	local HoverTween = TweenService:Create(
		Clone.TextLabel,
		TweenInfo.new(0.5),
		{
			Position = UDim2.new(0.1,0,0,0);
		}
	);

	local UnhoverTween = TweenService:Create(
		Clone.TextLabel,
		TweenInfo.new(0.25),
		{
			Position = UDim2.new(0.05,0,0,0);
		}
	);
	
	Clone.MouseButton1Click:Connect(function()

		SellFunctions[Number]();
	end);

	Clone.MouseEnter:Connect(function()

		HoverTween:Play();
	end);

	Clone.MouseLeave:Connect(function()

		UnhoverTween:Play();
	end);
end



local function NPCLookAt(NPC)
	
	local InFront = NPC.PrimaryPart.CFrame:ToObjectSpace(LocalPlayer.Character.PrimaryPart.CFrame).Z < 0;
	local unit = CFrame0 * CFrame.new(Vector3.new(0,0,0));

	if (NPC.PrimaryPart.Position - LocalPlayer.Character.PrimaryPart.Position).magnitude <= 26 and InFront then
		
		unit = -(NPC.PrimaryPart.CFrame.p - LocalPlayer.Character.PrimaryPart.Position).unit;
		NPCNeck.C0 = CFrame0 * CFrame.new(Vector3.new(0, 0, 0), unit);
	else
		
		if SellActive == true then
			
			CloseSell();
		end;
		
		local currentRotation = NPCNeck.C0;
		local targetRotation = CFrame0;
		local lerpValue = 0.1;

		NPCNeck.C0 = currentRotation:Lerp(targetRotation, lerpValue);
	end;
end;

RunService.RenderStepped:Connect(function(DeltaTime)
	
	if LocalPlayer.Character then

		NPCLookAt(SellNPC);
	end;
end);


and the billboardgui is in startergui

I don’t see any reason why this wouldn’t work. It’s possible you may have some other script that interferes with this.

1 Like

The problem is probably outside this script. There’s nothing inside that one script that may bug the system. Try adding prints and debug certain parts of the script, such as constantly printing for SellOptions existence. Make sure it is also replicating for user (even though I bet this is the problem, as it’s inside the local script)

i have no other scripts that does interact with the SellGUI

1 Like

By the way, are you storing the SellOptions variable after you pressed that one button? Or before that press?

i tried printing the fullname for the button initializations, the result was:
when it works: Players.marigold.PlayerGUI.SellOptions.1
when it doesn’t work however it shows: SellOptions.1

There’s a high chance SellOptions is not yet existent, but I don’t know for sure. Or player can’t access it somehow. But I don’t know because the video you sent shows that sometimes it works while sometimes it doesn’t

before the press, it was initially inside the BillboardGUI but it refused to replicate to the PlayerGui

1 Like

If it prints only SellOptions, does that mean he’s not yet parented to any objects? (When in this case it doesn’t work)

1 Like

Are you creating the options in a serverScript? Or local script only?

it can be found inside the explorer, just empty is all.

and it is being created with localscript

I understand now. Maybe the problem is when you are creating the SellOptions (1, 2, 3, 4); that’s why it prints out “1 is not a valid member […].” Can you send the code where you create the SellOptions textLabels, or is it already defined outside the script manually?

local BillboardGui = PlayerGui:WaitForChild(“SellOptions”);
BillboardGui.Adornee = SellNPC:WaitForChild(“HumanoidRootPart”); --For whatever reason it doesn’t work unless I add this
script.UIListLayout.Parent = BillboardGui;
for Number, Text in pairs(SellOptions) do

local Clone = script.Button:Clone();
Clone.Number.Text = string.format("#%s", Number);
Clone.TextLabel.Text = string.format("%s", Text);
Clone.Name = Number;

Clone.Parent = BillboardGui;

local HoverTween = TweenService:Create(
    Clone.TextLabel,
    TweenInfo.new(0.5),
    {
        Position = UDim2.new(0.1,0,0,0);
    }
);

local UnhoverTween = TweenService:Create(
    Clone.TextLabel,
    TweenInfo.new(0.25),
    {
        Position = UDim2.new(0.05,0,0,0);
    }
);

Clone.MouseButton1Click:Connect(function()

    SellFunctions[Number]();
end);

Clone.MouseEnter:Connect(function()

    HoverTween:Play();
end);

Clone.MouseLeave:Connect(function()

    UnhoverTween:Play();
end);

end

it doesn’t replicate to the playergui for whatever reason when it is defined outside a script

i’ve been boggling with this one specific problem for 2 days straight, i am considering rewriting the whole thing :upside_down_face:

Try creating the SellOptions with a ServerScript; I don’t know if it will solve the problem, but it’s not bad trying it ig

1 Like

i’ll give an update if this works or not

1 Like