Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Whats the problem with the chat tool script?

Asked by 5 years ago

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) 
0
try :FindFirstChild instead? stepatron 103 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

Ad

Answer this question