So I'm trying to make it so when I equip the tool, it will show up a gui. When you close it, it'll remove the gui. I don't know whats wrong so could anyone help? Thanks.
local tool = script.Parent -- Make sure that this script is in your tool local gui = game.ServerStorage.Chat local player = game.Players.LocalPlayer tool.Equipped:connect(function(mouse) local guiclone = gui:Clone() guiclone.Parent = player.PlayerGui-- assuming you already have "player" defined game.StarterGui:SetCoreGuiEnabled(3, true) end) tool.Unequipped:connect(function() if player.PlayerGui:findFirstChild("Chat") then player.PlayerGui:findFirstChild("Chat"):Destroy() -- removes "Gui" game.StarterGui:SetCoreGuiEnabled(3, false) end end)
You are using LocalPlayer and ServerStorage references in the same script.
LocalScripts do not have the ability to see ServerStorage or ServerScriptService. Local Scripts run a version of themselves on every person's screen. Scripts, on the other hand, cannot see a local player because they run on the server with all the players connecting and disconnecting around it.
Since I do not know the context of your project, I cannot fix your code. I can recommend you move shared assets to ReplicatedStorage, since as the name implies, anything there is replicated from the server to the client (and you put your remotes here to allow the client to add stuff too.)