Combining scripts into one

i know this is mostly a no brainer but im very tired and cant wrap my head around this

i have a module script with 4 tables (Shark, Admin, Moderator, Streamer) each table contains some player names and if a player who types in a chat have one of these 4 roles, they will have chat tags with the role that they have.

thing is i made 4 different scripts for each role and they seem to bug each other out, can someone help me combine them all please

SCRIPT1

local TextChatService = game:GetService("TextChatService")
local Properties = Instance.new("TextChatMessageProperties")
local r, g, b = 255, 0, 0 -- Change this to whatever color you want your tags to be.
local ChatTagText = "[Admin]" -- Change YourChatTagText to what you want your role to be.

  Admins = require(game.Workspace.Settings)

    local TagOwners = Admins.Admins -- Change "YourMAINRobloxUsername and S 
  omeoneelsesRobloxUsername"to who ever you want to have this ChatTag.

   TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
    if Message.TextSource then
	 local Player = game:GetService("Players"):GetPlayerByUserId(Message.TextSource.UserId)
	if table.find(TagOwners, Player.Name) then
		Properties.PrefixText = "<font color='rgb(" .. r .. "," .. g .. "," .. b .. ")'>" .. ChatTagText .. "</font> " .. Message.PrefixText
	end
end
return Properties
     end

SCRIPT2

  local TextChatService = game:GetService("TextChatService")
  local Properties = Instance.new("TextChatMessageProperties")
  local r, g, b = 0, 255, 0 -- Change this to whatever color you want your tags to be.
  local ChatTagText = "[Moderator]" -- Change YourChatTagText to what you want your role to be.

Moderator = require(game.Workspace.Settings)

 local TagOwners = Moderator.Mods -- Change "YourMAINRobloxUsername and 
 SomeoneelsesRobloxUsername"to who ever you want to have this ChatTag.

TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
      if Message.TextSource then
	local Player = game:GetService("Players"):GetPlayerByUserId(Message.TextSource.UserId)
	if table.find(TagOwners, Player.Name) then
		Properties.PrefixText = "<font color='rgb(" .. r .. "," .. g .. "," .. b .. ")'>" .. ChatTagText .. "</font> " .. Message.PrefixText
	end
end
return Properties
 end

SCRIPT3

 local TextChatService = game:GetService("TextChatService")
 local Properties = Instance.new("TextChatMessageProperties")
 local r, g, b = 0, 128, 255 -- Change this to whatever color you want your tags to be.
 local ChatTagText = "[Shark]" -- Change YourChatTagText to what you want your role to be.

Shark = require(game.Workspace.Settings)

local TagOwners = Shark.Shark -- Change "YourMAINRobloxUsername and 
SomeoneelsesRobloxUsername"to who ever you want to have this ChatTag.

TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
if Message.TextSource then
	local Player = game:GetService("Players"):GetPlayerByUserId(Message.TextSource.UserId)
	if table.find(TagOwners, Player.Name) then
		Properties.PrefixText = "<font color='rgb(" .. r .. "," .. g .. "," .. b .. ")'>" .. ChatTagText .. "</font> " .. Message.PrefixText
	end
end
return Properties
end

SCRIPT 4

local TextChatService = game:GetService("TextChatService")
local Properties = Instance.new("TextChatMessageProperties")
local r, g, b = 51, 153, 255 -- Change this to whatever color you want your tags to be.
local ChatTagText = "[Streamer]" -- Change YourChatTagText to what you want your role to be.

 Streamer = require(game.Workspace.Settings)

local TagOwners = Streamer.Streamers -- Change "YourMAINRobloxUsername and SomeoneelsesRobloxUsername"to who ever you want to have this ChatTag.

TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
if Message.TextSource then
	local Player = game:GetService("Players"):GetPlayerByUserId(Message.TextSource.UserId)
	if table.find(TagOwners, Player.Name) then
		Properties.PrefixText = "<font color='rgb(" .. r .. "," .. g .. "," .. b .. ")'>" .. ChatTagText .. "</font> " .. Message.PrefixText
	end
end
return Properties
 end

Anyone who does this is going to have a brain meltdown o-o

1 Like

im really sorry for potentially melting brains

1 Like

i’m really tired and sleepy right now idk if it’s gonna work lol

local TextChatService = game:GetService("TextChatService")
local Properties = Instance.new("TextChatMessageProperties")

local ranks = {
	Admin = {"[Admin]", 255, 0, 0}, -- {ChatTagText, r, g, b}
	Mod = {"[Moderator]", 0, 255, 0},
	Shark = {"[Shark]", 0, 128, 255},
	Streamer = {"[Streamer]", 51, 153, 255}
} -- i'm lazy

local whohasrank = require(game.Workspace.Settings)

TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
	if Message.TextSource then
		local Player = game:GetService("Players"):GetPlayerByUserId(Message.TextSource.UserId)
		if table.find(whohasrank.Admins, Player.Name) then
			local thing = ranks.Admin
			Properties.PrefixText = "<font color='rgb(" .. thing[2] .. "," .. thing[3] .. "," .. thing[4] .. ")'>" .. thing[1] .. "</font> " .. Message.PrefixText
		elseif table.find(whohasrank.Mods, Player.Name) then
			local thing = ranks.Mod
			Properties.PrefixText = "<font color='rgb(" .. thing[2] .. "," .. thing[3] .. "," .. thing[4] .. ")'>" .. thing[1] .. "</font> " .. Message.PrefixText
		elseif table.find(whohasrank.Shark, Player.Name) then
			local thing = ranks.Shark
			Properties.PrefixText = "<font color='rgb(" .. thing[2] .. "," .. thing[3] .. "," .. thing[4] .. ")'>" .. thing[1] .. "</font> " .. Message.PrefixText
		elseif table.find(whohasrank.Streamers, Player.Name) then
			local thing = ranks.Streamer
			Properties.PrefixText = "<font color='rgb(" .. thing[2] .. "," .. thing[3] .. "," .. thing[4] .. ")'>" .. thing[1] .. "</font> " .. Message.PrefixText
		end
	end
	return Properties
end
1 Like
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local Properties = Instance.new("TextChatMessageProperties")
local Settings = require(game.Workspace.Settings)

--[[
	The key is the ChatTagText.
	Owners is the table of who own the rank.
	Color3 is the color of the tag.
]]

local RANKS = {
	Admin = {
		Owners = Settings.Admins,
		Color3 = { 255, 0, 0 },
	},
	Moderator = {
		Owners = Settings.Mods,
		Color3 = { 0, 255, 0 },
	},
	Shark = {
		Owners = Settings.Shark,
		Color3 = { 0, 128, 255 },
	},
	Streamer = {
		Owners = Settings.Streamers,
		Color3 = { 51, 153, 255 },
	},
}

TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
	if not Message.TextSource then
		return Properties
	end

	local player = Players:GetPlayerByUserId(Message.TextSource.UserId)
	for key, rank in RANKS do
		if not table.find(rank.Owners, player) then
			continue
		end
		local tagColors = rank.Color3
		local tagString = `<font color='rgb({tagColors[1]}, {tagColors[2]}, {tagColors[3]})'>[{key}]</font>`
		Properties.PrefixText = `{tagString} {Message.PrefixText}`
	end

	return Properties
end

this one did the trick thank you so much!!

hello thanks for trying but it did not work, somebody replied and their solution worked but still thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.