Sending Chat Message from Local Script not working

I am trying to send the message hello through script, but I got this error: StarterGui:SetCore must be called from a local script. even though i didnt use setcore on the server script. Everything is printing right, such as “message sent” but why is the chat message still not there?

Server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteFunction = ReplicatedStorage:WaitForChild("AdminUpdateRF")

function sendAnnouncement(message)
    local players = game:GetService("Players"):GetPlayers()
    for _, player in ipairs(players) do
        remoteFunction:InvokeClient(player, message)
    end
end

sendAnnouncement("Hello")

Local Script:

local remoteFunction = game:GetService("ReplicatedStorage"):WaitForChild("AdminUpdateRF")
local StarterGui = game.StarterGui

remoteFunction.OnClientInvoke = function(newAdminName)
    local message = newAdminName
    StarterGui:SetCore("ChatMakeSystemMessage", {
        Text = message,
        Color = Color3.new(1, 1, 1),
        Font = Enum.Font.SourceSansBold,
        TextSize = 18
    })
    print("message sent")
end

OnClientInvoke returns the function you set the callback to, so it’s actually trying to run it on the server.
Try using a remote event instead.

1 Like