Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how can i send a system message back like "not found" on the chat when i enter a command?

i tryed this but get back the channel is nil and the warn is only for server message for output

local AdminCommands = require(1163352238)
local Utilities = AdminCommands.Utilities

local ZombyGame = "/zombie "

local function onOwnerChatted(player, message, channel)

	if message:sub(1, ZombyGame:len()):lower() == ZombyGame:lower() then
	
		local aMessage = message:sub(ZombyGame:len() + 1)
	
		if aMessage == "on" then
		
			local zombiegame = game.ReplicatedStorage.MiniGames:FindFirstChild("ZombieGame")
		
			if zombiegame then
		
				zombiegame.Parent = workspace
			
			else
			
				warn "Not Found"
				channel:SendSystemMessage ( "Not Found" )
			
			end
		
		end
	
		if aMessage == "off"then
		
			local zombiegame = workspace:FindFirstChild("ZombieGame")
		
			if zombiegame then
			
				zombiegame.Parent = game.ReplicatedStorage.MiniGames
			
			else
			
				warn "Not Found"
				channel:SendSystemMessage ( "Not Found" )
			
			end
		
		end
	
	end
end

local function onPlayerAdded(player)
-- Restrict this command to only the creator/owner
	local Name = lol --my name
	local Id = 123456789 --my id change this both

	if player.UserId == game.CreatorId and game.CreatorType == Enum.CreatorType.User or player.Name == Name and player.UserId == Id then
		player.Chatted:Connect(function (...)
			onOwnerChatted(player, ...)
		end)
	end

end

-- Listen for players being added
for _, player in pairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)

i did have made my own channel and this script is a normale script in ServerScriptService

1 answer

Unfortunately you can not send a system message from a regular script. It must be called from a localscript. What you can do is have a localscript inside starter player scripts (or StarterGui) that listens for a remote event. Here's how I'd approach it (Untested):

 -- Local Script (game.StarterPlayer)
local event = game:GetService("ReplicatedStorage"):FindFirstChild("ServerMessage")
if nil == event then
    repeat
        event = game:GetService("ReplicatedStorage"):WaitForChild("ServerMessage", 10)
        wait(0.1)
    until nil ~= event
end
event.OnClientEvent:Connect(function(message, font, font_size, brick_color)
    brick_color, font, font_size = brick_color or BrickColor.new("Dark stone grey"), font or Enum.Font.Cartoon, font_size or  Enum.FontSize.Size96
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {
        Text = tostring(message or "Hello World"),
        Font = font,
        Color = brick_color.Color,
        FontSize = font_size
    })
end)
-- Script in ServerScriptService
function SystemMessage(...)
    spawn(function()
        local event = game:GetService("ReplicatedStorage"):FindFirstChild("ServerMessage")
        if nil == event then
            event = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
            event.Name = "ServerMessage"
            wait(1.25)
        end
        if nil ~= event then
            event:FireAllClients(...)
        end
    end)
end

SystemMessage("Lz was here")

2 comments

0

ok so i have to make an event for that so when in my script its not found i have to fire that event

0

There are countless variations but basically, yes.

This discussion is preserved as it was. New answers, comments, and votes are closed.