Tool won't create BillboardGui when equipped

Hey! I’m trying to create a tool that inserts a BillboardGui into other players characters when equipped, and remove it when unequipped.
Basically a tool to know a players location when you equip it.

I have tried creating the BillboardGui with Instance.new(), using a server script (while removing the LocalPlayer and the if requirement), removing all if checks to see if the script errors but nothing, I don’t even get an error there. I have also tried inserting it into the characters head but with no success.
I also tried setting the BillboardGui adornee at the same time but nothing.

Here’s the code:

local tool = script.Parent
local GUIFolder = tool:WaitForChild("GUI")
local GUI = GUIFolder:WaitForChild("Hitmark"):Clone()

local players = game:GetService("Players")
local selfplayer = players.LocalPlayer

local function findPlayer()
	for i, plr in pairs (players:GetPlayers()) do
		if plr.Name ~= selfplayer.Name then
			local char = plr.Character or plr.CharactedAdded:Wait()
			if char then
				if not char:FindFirstChild("Hitmark") then
					GUI.Enabled = true
					GUI.Parent = char
				end
			end
		end
	end
end

local function removeGUI()
	for i, plr in pairs (players:GetPlayers()) do
		local char = plr.Character or plr.CharactedAdded:Wait()
		if char then
			for i, stuff in pairs (char:GetChildren()) do
				if stuff.Name == "Hitmark" then
					stuff:Destroy()
				end
			end
		end
	end
end

tool.Equipped:Connect(findPlayer)
tool.Unequipped:Connect(removeGUI)
1 Like

Try parenting it to char.HumanoidRootPart

Also tried parenting it to that and the characters head but nothing

I’m soo confused

I would first rewrite your script so that local GUI = GUIFolder:WaitForChild("Hitmark"):Clone() is written after if not char:FindFirstChild("Hitmark") then so that the GUI is created each time it needs to be, rather than only once. Next, I would add a print statement to this same scope where you clone + enable the GUI. if nothing is printed, then there is something wrong with the code leading up to this moment. If something is printed, then there is an issue with the actual GUI itself.

Thank you for that suggestion, just applied it.

Added the print statement, but nothing was printed. Hmm, looks like it’s something wrong with the code.

It seems it’s not even detecting the tool is being equipped. Added a print statement right when the function starts, but nothing was printed.
Weird, the LocalScript is inside the tool

Is there by any chance an infinite yield on your :WaitForChild() statements, or maybe you just didn’t wait long enough?

Waited about a minute and didn’t get an infinite yield error.
Here’s the tool structure
image

And here’s the BillboardGui on a test dummy.
image

I’m so confused as to why it’s not even printing anything

That’s… kinda weird. I guess all I could recommend doing is now insert a print literally between each of the above lines, something must be preventing the code from running, because I can’t think of a reason that the .Equipped event wouldn’t be fired when you equip the tool.

Oh my, I just found out why it’s not even running. I completely forgot to disable the RequiresHandle property on the Tool, that’s why nothing was ran.

Thank you for your help!

1 Like