Module spellcast system printing my username instead of spell Why?

I’m trying to create a spell casting system using a module script, but it’s printing this:

20:19:30.487 Funnyskyswagway3 is not a valid spell. - Server - SpellSystem:18

local Spells = game.ReplicatedStorage.SpellModules
local SpellSystem = {}

SpellSystem.Spells = {
	["Teleport"] = {
		Activate = Spells.Teleport
	}

}

function SpellSystem.Spells.AddSpell(self, spellName, spellFunction)
	self.Spells[spellName].Activate = spellFunction
end

function SpellSystem:CastSpell(player, spellName, ...)
	local spell = self.Spells[spellName]
	if not spell then
		warn(tostring(spellName).." is not a valid spell.")
		return
	end

	spell.Activate(player, ...)
end
print(SpellSystem.Spells)
return SpellSystem

How are you calling :CastSpell()?

It is being called from a local script.

Show code.

123456789123456789123456

local SpellSystem = require(game.ReplicatedStorage.SpellSystem)

local function parseChat(player)
	game.Players.LocalPlayer.Chatted:Connect(parseChat(),function(message)
		local words = {}

		for word in message:gmatch("%w+") do
			table.insert(words, word)
		end

		local spellName = words[1]
		if SpellSystem.Spells[spellName] then
			table.remove(words, 1)

			SpellSystem:CastSpell(player, spellName, unpack(words))
		end
	end)
end

Your call to :Connect() is misleading. You are actually passing the player’s name as “message” to your anonymous function. I believe your script should look like this:

game.Players.LocalPlayer.Chatted:Connect(function(message, recipient)
	local words = {}

	for word in message:gmatch("%w+") do
		table.insert(words, word)
	end

	local spellName = words[1]
	if SpellSystem.Spells[spellName] then
		table.remove(words, 1)

		SpellSystem:CastSpell(player, spellName, unpack(words))
	end
end)

20:35:36.949 ReplicatedStorage.SpellSystem:21: attempt to call a Instance value - Client - SpellSystem:21

When the spell is said in chat this is the error.

You can’t expect me to know what went wrong when there isn’t a line 21 in what I gave you.

Line 21 is in the module script.

spell.Activate is an Instance and not a function, so you can’t call it.