Trying to get a team from a part of a string

I wanted to make a module that finds the team from a string, however I’ve tried everything but the same error:

Workspace.Main.AssistantModule:39: attempt to get length of a Instance value  -  Server - AssistantModule:39
-- CODE OF MODULE.
function HelpfulModule.get_Team(team_name: "A team name")
	if not game.Teams:FindFirstChild(team_name) then return end
	
	local lower_team_name = string.lower(team_name)
	for _, team_name in pairs(game.Teams:GetTeams()) do
		if team_name:sub(1,#team_name):lower() == lower_team_name then
			return team_name
		end
	end
end
-- CODE THAT RUNS THE MODULE.

elseif string.sub(args[2], 1, 1) == "%" then
		local TargetHumanoid = player.Character:WaitForChild("Humanoid")
		local team = helpfulModule.get_Team(args[2]:sub(2))
		
		for i, peopleInTeam in game.Players:GetPlayers() do
			if peopleInTeam.Team == nil then return end
			if peopleInTeam.Team == team then
				
				
				target = peopleInTeam
				
				local TargetHumanoid = player.Character:WaitForChild("Humanoid")
				local PlayerHumanoid = target.Character:WaitForChild("Humanoid")
				local LastTargetPosition = TargetHumanoid.RootPart.CFrame
				local Length = 3 -- Length between player and target player

				PlayerHumanoid.RootPart.CFrame = LastTargetPosition + LastTargetPosition.LookVector * Length
				PlayerHumanoid.RootPart.CFrame = CFrame.new(PlayerHumanoid.RootPart.CFrame.Position, Vector3.new(LastTargetPosition.Position.X, PlayerHumanoid.RootPart.CFrame.Position.Y, LastTargetPosition.Position.Z))
			end
		end

Even thought It says the error there, I cannot figure out why it is doing that.

The error says exactly what’s wrong, you’re trying to get the length of something that is not a string. The :GetTeams() method returns a table of Team objects: Team | Documentation - Roblox Creator Hub

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