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)
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
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?
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.
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)
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)