I looked this up but this code does not work for some reason:
local StarterGui = game:GetService('StarterGui') StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
To use SetCoreGuiEnabled, it must be a LocalScript within a Player (ex: Backpack, PlayerGui, etc.). The script you have is fine, though.
The script is okay, but this needs to be in a LocalScript.
I suggest putting it inside StarterPlayerScripts