Always passing nil

Hey, so right now I am working on a abilitymanager module script with stats and a moveset set in the player. Now that moveset is stored in a stringValue of which I thought is the way I should do it.
For some reason I always get nil as the parameter at where I want to change this value

-- this is in the module script
function AbilityManager:ChangeAbility(player: Player, abilityName: string)
	if type(abilityName) ~= "string" then
		warn("Invalid ability name type:", typeof(abilityName))
		return
	end

	local abilityData = MoveSets[abilityName]
	if not abilityData then
		warn("Ability not found:", abilityName)
		return
	end

	local stats = player:WaitForChild("PlayerStats")
	stats.Ability.Value = abilityName
end
--this is in the server script
Player.PlayerAdded:Connect(function(player)
	
	playerData[player.UserId] = Abilitymanager:CreateNewInfo(player)
 	local set = MoveSets[player.PlayerStats.Ability.Value]
	
	Abilitymanager.ChangeAbility(player, "TestMoveset2")
end)

And this is how the movesets are stored

local MoveSets = {
	TestMoveset1 = {
		{["Name"] = "Test1", ["Cooldown"] = 5, ["Input"] = "E"},
		{["Name"] = "Test2", ["Cooldown"] = 5, ["Input"] = "R"},
		{["Name"] = "Test3", ["Cooldown"] = 5, ["Input"] = "T"}
	},
	
	TestMoveset2 = {
		{["Name"] = "Test1", ["Cooldown"] = 5, ["Input"] = "E"},
		{["Name"] = "Test2", ["Cooldown"] = 5, ["Input"] = "R"},
		{["Name"] = "Test3", ["Cooldown"] = 5, ["Input"] = "T"}
	}
}


return MoveSets

I think it is a type but I tried changing it to a string and using .Value but it still give nil.

Thank you for reading.

Could it be that you just called the function incorrectly

In the 1st codeblock it’s like AbilityManager:ChangeAbility

so then logically you’d call it like this AbilityManager:ChangeAbility(player,“TestMoveset2”)

1 Like

Adding onto what @NxYz said, defining a function with a colon is just shorthand for including the table itself as the first parameter

-- These are the same thing
function AbilityManager:ChangeAbility(player: Player, abilityName: string) end
function AbilityManager.ChangeAbility(self: AbilityManager, player: Player, abilityName: string)

The same rule applies when calling functions too

-- These calls pass the same exact arguments to the function
AbilityManager:ChangeAbility(player, "TestMoveset2")
Abilitymanager.ChangeAbility(Abilitymanager, player, "TestMoveset2")
2 Likes

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