ERROR: OnServerEvent can only be used on the server
LocalScript1:
--local Settings = require(game.ServerScriptService.Settings)
local plr = game.Players.LocalPlayer
local chat = game.ReplicatedStorage.ChatHistory
local last
local GroupId = 2642682 --Settings.Groupe.GroupId
-------------------------------------------------------------------------------------------------
function newChat(msg,plr)
if #msg > 0 then
for i, c in pairs(chat:GetChildren()) do
c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
end
local newMessage = script.Msg:clone()
if #chat:GetChildren() == 6 then
chat:GetChildren()[1]:Destroy()
end
if plr.TeamColor == BrickColor.new("Bright red") then
newMessage.Text = "[RAIDER] "..plr.Name..": "..msg
newMessage.Raider.Visible = true
print(plr.Name.." is raider")
else
newMessage.Rank.Text = "["..plr:GetRoleInGroup(GroupId).."] "
newMessage.Text = "["..plr:GetRoleInGroup(GroupId).."] "..plr.Name..": "..msg
newMessage.Rank.Visible = true
end
newMessage.Visible = true
newMessage.Parent = chat
newMessage.Position = UDim2.new(0, 0, 0.6, 0)
last = newMessage
wait(60)
last:Destroy()
end
end
-------------------------------------------------------------------------------------------------
function newChatServer(plr,msg)
for i, c in pairs(chat:GetChildren()) do
c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
end
local newMessage = script.Msg:clone()
if #chat:GetChildren() == 6 then
chat:GetChildren()[1]:Destroy()
end
newMessage.Rank.Text = "["..plr:GetRoleInGroup(GroupId).."] "
newMessage.Text = "[SERVER] "..plr.Name..msg
newMessage.Server.Visible = true
newMessage.Visible = true
newMessage.Parent = chat
newMessage.Position = UDim2.new(0, 0, 0.6, 0)
last = newMessage
wait(60)
last:Destroy()
end
-------------------------------------------------------------------------------------------------
game.Players.LocalPlayer.Chatted:connect(function(msg)
newChat(msg, plr) print("newChat")
game.ReplicatedStorage.RemoteEvent.NewMsg:FireServer(plr, msg) print("FireChatService")
end)
-------------------------------------------------------------------------------------------------
game:GetService("ReplicatedStorage").RemoteEvent.SwitchTeam.OnServerEvent:connect(function(plr)
local msg = " switch team to "..plr.Team.Name.."!"
newChatServer(plr,msg)
game.ReplicatedStorage.RemoteEvent.NewMsg:FireServer(plr, msg) print("FireChatService")
end)
-------------------------------------------------------------------------------------------------
LocalScript2:
script.Parent.MouseButton1Click:connect(function()
game.Players.LocalPlayer.TeamColor = BrickColor.new("Bright red")
------------------------------------------------------------------------
game:GetService("ReplicatedStorage").RemoteEvent.LoadChar:FireServer() --game.Players.LocalPlayer:LoadCharacter()
game:GetService("ReplicatedStorage").RemoteEvent.SwitchTeam:FireServer()
------------------------------------------------------------------------
print(game.Players.LocalPlayer.Name,"has changed team to",script.Parent.Name)
end)

2 comments
if you're not communicating from client to server or vice-versa, just use a bindable event/function
Fire/Invoke client and server are used to communicate between the client(local datamodel) and server(global datamodl). If you wish to fire client to server, you need to have the local script wait for the eventInstance and then fire it, however there needs to be a nonlocal script in the server to fire the "ServerEven"