System messages

Hey developers,
I have this script that should fire server and create a server message, but it doesnt work ( i think its that i dont know how to check the players that touches the part, name )
this is what output shows:
image
and the scripts:
(ServerScriptService)

local banpart = game.Workspace.Part
local RS = game:GetService("ReplicatedStorage")
local Ban = RS.Ban


banpart.Touched:Connect(function(otherPart)
	local plrtoban = otherPart.Parent.Parent
	Ban:FireClient(plrtoban)
end)

(StarterGui)

local RS = game:GetService("ReplicatedStorage")
local banevent = RS.Ban

banevent.OnClientEvent:connect(function(player, plrtoban)
	local plrtobanName = plrtoban.Name
	
	game.StarterGui:SetCore("ChatMakeSystemMessage", 
	{
		Text = "SYSTEM: "..plrtobanName.. "was RAC banned",
		Color = Color3.fromRGB(5, 255, 63),
		Font = Enum.Font.SourceSansBold,
		TextSize = 18,
		})
	
end) 
1 Like

Firstly, this InsertService error in your output is not being caused by this part of your code.

There are, however, a few things wrong with both your client and server code. The arguments you’re passing in FireClient() are wrong. You probably want to use RemoteEvent:FireAllClients() (as seen in the example below) on the server to send a system message to the whole server whenever someone is banned.

-- your server script
local banPart = game.Workspace.Part
local RS = game:GetService("ReplicatedStorage")
local Ban = RS.Ban

banPart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then -- check if the thing that touched the part has a humanoid
        local plrToBan = game.Players:GetPlayerFromCharacter(hit.Parent) -- attempt to get the player from the character
        if plrToBan then -- check that the player to ban exists
            Ban:FireAllClients(plrToBan) -- fire the plrToBan to the whole server 
        end
    end
end)
-- your local script in StarterGui
local RS = game:GetService("ReplicatedStorage")
local BanEvent = RS.Ban

BanEvent.OnClientEvent:Connect(function(plrToBan)
    local plrToBanName = plrToBan.Name
    
    game.StarterGui:SetCore("ChatMakeSystemMessage", 
        {
		    Text = "SYSTEM: "..plrToBanName.. " was RAC banned",
		    Color = Color3.fromRGB(5, 255, 63),
		    Font = Enum.Font.SourceSansBold,
		    TextSize = 18,
		})
end)

Some documentation/resources that you might find useful:
Open Source System Message Code by LegendOJ1
RemoteEvent:FireAllClients
RemoteEvent:FireClient
StarterGui:SetCore
Players:GetPlayerFromCharacter

2 Likes