Help with ModuleScripts

I want to keep my Group chat tags a bit clean and putting my roles inside a module script. But I can’t seem to make it work

The error is: ServerScriptService.GroupRelatedStuff.Chat tags:22: attempt to index function with ‘Founder’

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

local GroupRoles = require(ReplicatedStorage.Modules.GroupRanks)
local chatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

local plrs = game.Players
local groupId = 7628430

chatService.SpeakerAdded:Connect(function(plr)
	local speaker = chatService:GetSpeaker(plr)
	if plrs[plr]:IsInGroup(groupId) then        
		local PlayerRank = plrs[plr]:GetRoleInGroup(groupId)
		speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
		speaker:SetExtraData('Tags', {{TagText = PlayerRank, TagColor = GroupRoles.GroupRanks[PlayerRank]}})    
	else
		speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
		speaker:SetExtraData('Tags', {{TagText = "Guest", TagColor = Color3.fromRGB(255, 255, 127)}})
	end
end)




Module Script:

local module = {}

function module.GroupRanks()
	local Colours = {
		
		--Rankings--
		["Founder"] = ColorSequence.new(Color3.new(0, 0, 1),Color3.new(0, 0.333333, 1));
		["Admin"] = ColorSequence.new(Color3.new(1, 0.666667, 0),Color3.new(1, 1, 0));
		["Mod"] = ColorSequence.new(Color3.new(0.333333, 0, 0.498039),Color3.new(0.72549, 0, 0.72549));
		["Tester"] = ColorSequence.new(Color3.new(1, 0.635294, 0),Color3.new(0.796078, 0.231373, 0.00784314));
		["Developer"] = ColorSequence.new(Color3.new(1, 1, 0),Color3.new(0.796078, 0.466667, 0.180392));
		["Member"] = ColorSequence.new(Color3.new(1, 0, 0.498039),Color3.new(1, 0.333333, 1));
	}
end

return module
1 Like

You’re not even calling the function here, and the function itself doesn’t return anything, so you’ll have to fix that by returning the dictionary and calling the function instead of trying to index something with it.

ModuleScript function:

function module.GroupRanks()
	local Colours = {

		--Rankings--
		["Founder"] = ColorSequence.new(Color3.new(0, 0, 1),Color3.new(0, 0.333333, 1));
		["Admin"] = ColorSequence.new(Color3.new(1, 0.666667, 0),Color3.new(1, 1, 0));
		["Mod"] = ColorSequence.new(Color3.new(0.333333, 0, 0.498039),Color3.new(0.72549, 0, 0.72549));
		["Tester"] = ColorSequence.new(Color3.new(1, 0.635294, 0),Color3.new(0.796078, 0.231373, 0.00784314));
		["Developer"] = ColorSequence.new(Color3.new(1, 1, 0),Color3.new(0.796078, 0.466667, 0.180392));
		["Member"] = ColorSequence.new(Color3.new(1, 0, 0.498039),Color3.new(1, 0.333333, 1));
	}
	
	return Colours
end

Also replace the error line; (speaker:SetExtraData('Tags', {{TagText = PlayerRank, TagColor = GroupRoles.GroupRanks()[PlayerRank]}}))

Thank you, that worked out well.