local Gui
script.Parent.Equipped:Connect(function()
if not Gui then
Gui = script.Gui:Clone()
end
Gui.Parent = game.Players.LocalPlayer.PlayerGui
end)
script.Parent.Unequipped:Connect(function()
if Gui then
Gui:Destroy()
end
end)
-- This script should be a LocalScript
local tool = script.Parent
tool.Equipped:Connect(function()
print("Tool equipped")
local Gui = script:FindFirstChild("Gui")
if Gui then
local clonedGui = Gui:Clone()
clonedGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
print("Gui cloned and parented to PlayerGui")
else
warn("Gui not found in the script")
end
end)
tool.Unequipped:Connect(function()
print("Tool unequipped")
local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local mapGui = playerGui:FindFirstChild("Map")
if mapGui then
mapGui:Destroy()
print("Map GUI destroyed")
else
warn("Map GUI not found in PlayerGui")
end
end)
I just have another issue with another tool, where it won’t clone into the player’s backpack from serverstorage. I have other tools that do the same and they work but for some reason one of them doesn’t do anything at all and won’t clone unless I manually drag it from serverstorage into the player through the explorer.
workspace['Event'].Event:Connect(function(player,item)
game.ServerStorage[item]:Clone().Parent=player.Backpack
end)
workspace.Part.Touched:Connect(function(hit) -- there was no debounce soo it willl be multiple problem
if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name)then
workspace.Event:Fire(
'Name Tool', -- item
game.Players[hit.Parent.Name] -- player
)
end
end)