Dress function working incorrectly

Hi, So i have a function that is meant to dress a GROUP of characters with the following code:

function module.DressTeam2(team2)
	local character
	for i, v in pairs (team2) do
		if v.EquippedTeam2Skin.Value ~= "" then
		*	if game.ReplicatedStorage.Team2Skins:FindFirstChild(team2.EquippedTeam2Skin.Value) then
				character = game.ReplicatedStorage.Team2Skins[team2.EquippedTeamSkin.Value]:Clone()
				end	
			else
			character = game.ReplicatedStorage.Team2Skins.DefaultTeam2:Clone()
			end
		

		character.Name = team2.Name
		teamn2.Character = character
		character.Parent = workspace
		end
end

So this code seems to break my game (breaking alot of the round code etc)
With this error
ServerScriptService.GameLogic.RoundModule:74: attempt to index nil with 'Value'
(I have put an * in the code next to the line it is referring to)

For context, I will attach a similar script which DOES work below, however this is only to dress one player as opposed to many (Therefore I believe that is where the problem lies)

function module.DressTeam1(team1)
	local character
	if team1.EquippedTeam1Skin.Value ~= "" then
		if game.ReplicatedStorage.Team1Skins:FindFirstChild(team1.EquippedTeam1Skin.Value) then
			character = game.ReplicatedStorage.Team1Skins[team1.EquippedTeam1Skin.Value]:Clone()
		end	
	else
		character = game.ReplicatedStorage.Team1Skins.DefaultTeam1:Clone()
				
	end
	
	character.Name = team1.Name
	team1.Character = character
	character.Parent = workspace
end

hope this makes sense, thanks!

UPDATE: Ive altered the code a bit , now i seem to get this message (obviously due to the way I have defined character). Ive put the normal names in to reduce confusion.
function module.DressAssassin(assassin)

	for i, v in pairs (assassin) do
		if v.Character then
			local character = v.Character
			if v.EquippedAssassinSkin.Value ~= "" then
				if game.ReplicatedStorage.AssassinSkins:FindFirstChild(assassin.EquippedAssassinSkin.Value) then
					character = game.ReplicatedStorage.AssassinSkins[assassin.EquippedAssassinSkin.Value]:Clone()
				end	
			else
				character = game.ReplicatedStorage.AssassinSkins.DefaultAssassin:Clone()
			end


			character.Name = assassin.Name
			assassin.Character = character
			character.Parent = workspace
		end
	end
end

With which I get this error message.
`ServerScriptService.GameLogic.RoundModule:65: invalid argument #3 (string expected, got nil) -
Which referes to the
character.Name = assassin.Name
Part

Any ideas?
All help greatly appreciated :slight_smile:

Do v.EquippedTeam2Skin.Value rather than team2.EquippedTeam2Skin.Value because you’re checking to see if the player in team2’s value exist, not checking to see if team2’s skin exists.

Hi thanks for your reply i really appreciate it,
Using this newly implemented code:

function module.DressAssassin(assassin)

	for i, v in pairs (assassin) do
		if v.Character then
			local character = v.Character
			if v.EquippedAssassinSkin.Value ~= "" then
				if game.ReplicatedStorage.AssassinSkins:FindFirstChild(v.EquippedAssassinSkin.Value) then
					character = game.ReplicatedStorage.AssassinSkins[v.EquippedAssassinSkin.Value]:Clone()
				end	
			else
				character = game.ReplicatedStorage.AssassinSkins.DefaultAssassin:Clone()
			end


			character.Name = assassin.Name
			assassin.Character = character
			character.Parent = workspace
		end
	end
end

I get the following error
ServerScriptService.GameLogic.RoundModule:66: invalid argument #3 (string expected, got nil)

Which is referring to the character.Name = assassin.Name line
Any ideas?

Try v.Name rather than assassin.Name

1 Like

Of Course! Been looking at it for so long Im starting to miss small things. thank you so much!

2 Likes