Tool UI Handler Not Working

The script returns no errors at all, and simply does not work!

local Tool = script.Parent
local Player = game:GetService("Players"):FindFirstChild(Tool.Parent.Name)

Tool.Equipped:Connect(function()
	local UI = Tool:WaitForChild("Tool_Interface")
	UI.Parent = Player:WaitForChild("PlayerGui")
	UI.Updater.Enabled = true
end)

Tool.Unequipped:Connect(function()
	local UI = Player.PlayerGui:FindFirstChild("Tool_Interface")
	if UI then
		UI.Updater.Enabled = false
		UI.Parent = Tool
	end
end)

image

1 Like

That is likely because the Tool’s parent will be the Player’s Backpack, not the Player object itself. Trying adding .Parent.Parent and seeing if it helps :slight_smile:

When the tool is pulled out, the parent will be the players character.

game.Workspace.RenderedPhysics.TestingUI
1 Like

Ah, sorry my bad I was just doing something on the side. Have you tried print()ing after enabling the UI and so on and so forth, does it reach the print?

The script doesn’t return anything at all, almost as if it isn’t running.

Add a print statement for Player, and UI. Tell us the results

Ah, I see, the Player itself will likely be NIL at the start of execution as the tool will not be immediately pulled out.

Nothing is returned, as stated it’s almost as if the script isn’t running.

Also maybe try making the script a localscript. Equipped and Unequipped might be client specific events

My best guess is that this piece of code:

local Player = game:GetService("Players"):FindFirstChild(Tool.Parent.Name)

will run at the beginning of the game, and return the incorrect object since the Tool.Parent will be StarterPack and will thus return the string “StarterPack”, it will not :FindFirstChild() of name StarterPack in Players service, and return nil.

When the tool is finally equipped, it will reach:

UI.Parent = Player:WaitForChild("PlayerGui")

and thus stop execution since its trying to find PlayerGui in NIL.

Trying moving the local Player inside the functions.

That could be a possibility, maybe changing it to Tool.Parent.Parent will fix that.

Converted as localscript as

local Tool = script.Parent
local Player = game:GetService("Players").LocalPlayer

Tool.Equipped:Connect(function()
	local UI = Tool:WaitForChild("Tool_Interface")
	UI.Parent = Player:WaitForChild("PlayerGui")
	UI.Updater.Enabled = true
end)

Tool.Unequipped:Connect(function()
	local UI = Player.PlayerGui:FindFirstChild("Tool_Interface")
	if UI then
		UI.Updater.Enabled = false
		UI.Parent = Tool
	end
end)

yet still doesnt work or return any errors

Try moving the local Player declaration inside equipped and unequipped separately, only keeping the Tool declared outside. Report back if it doesn’t work. Check my other reply for the justification:

Place it in a serverscript as before.

local Tool = script.Parent

Tool.Equipped:Connect(function()
        local Player = game:GetService("Players"):FindFirstChild(Tool.Parent.Name)

	local UI = Tool:WaitForChild("Tool_Interface")
	UI.Parent = Player:WaitForChild("PlayerGui")
	UI.Updater.Enabled = true
end)

Tool.Unequipped:Connect(function()
        local Player = game:GetService("Players"):FindFirstChild(Tool.Parent.Name)

	local UI = Player.PlayerGui:FindFirstChild("Tool_Interface")
	if UI then
		UI.Updater.Enabled = false
		UI.Parent = Tool
	end
end)

Still does not work at all…

characterlimit

Give me a moment, I’ll open up studio and see what does work and send it back to you.

The actual model is here.

1 Like

Ah, hahahaha. This was actually quite funny, the tool was missing a handle and thus didn’t register the Equipped and Unequipped event at all.

You are getting the Player with the tool wrong let me see if I can find code as an example that can help you.

1 Like


Make sure your tool has a handle by the way so both Equipped and Unequipped events work.

1 Like

It works fine now. Just added a Handle, cheers!