For loop only cloning model to one player instead of every player

I am trying to use a for loop to clone a glove model to every player when they join the game.

The issue is that I can’t get the for loop to stop working for just one player. Here is an image of what I mean.
image

I have tried looking for solutions, but haven’t had much luck.

Here is a part of the code I am having a problem with.

for i, v in ipairs(lvl) do
	if v.TypeVal.Value == player.gloveLVL.Value then
		CloneFunction(v.TypeVal.Parent)
		print(v.TypeVal.Parent)
		print(i,v)
	end
end

The script only prints the intvalue parent model once.

It could be the way Clonefunction or the way the table is made, could you show the rest of the code so we could see if the issue is around there?

Ok, I’ll show the rest here.

local bg = game.ReplicatedStorage.BG
local plr = game:GetService("Players")
local lvl = {}

plr.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(char)
		lvl = {
			bg.BaseGloves;
			bg.BaseGloves2
		}
		local function CloneFunction(nxtGlove)
			local rHand = char:FindFirstChild("RightHand")
			local lHand = char:FindFirstChild("LeftHand")
			local gClone = nxtGlove:Clone()
			local g1Clone = gClone.RightGlove
			local g2Clone = gClone.LeftGlove
			local g1c_Weld = gClone.RightGlove.WeldConstraint
			local g2c_Weld = gClone.LeftGlove.WeldConstraint
			wait(0.3)
			gClone.Parent = char
			g1Clone.CFrame = char.RightHand.CFrame * CFrame.Angles(0,0,0) * CFrame.new(0,.169,0)
			g2Clone.CFrame = char.LeftHand.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0,.169,0)
			g1c_Weld.Part1 = char:FindFirstChild("RightHand")
			g2c_Weld.Part1 = char:FindFirstChild("LeftHand")
			g1Clone.CFrame = char.RightHand.CFrame * CFrame.Angles(0,0,0) * CFrame.new(0,.169,0)
			g2Clone.CFrame = char.LeftHand.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0,.169,0)
			g1Clone.CanCollide = false
			g2Clone.CanCollide = false
		end
		
		for i, p in ipairs(game.Players:GetChildren()) do
			print(i,p)
			if p then
				for i, v in ipairs(lvl) do
					if v.TypeVal.Value == player.gloveLVL.Value then
						CloneFunction(v.TypeVal.Parent)
						print(v.TypeVal.Parent)
						print(i,v)
					end
				end
			end
		end
			
	char.Humanoid.Died:Connect(function(hum)
			wait(3)
			player:LoadCharacter()
		end)
	end)
	wait(3)
	player:LoadCharacter()
end)

There’s a few things that are confusing me, Firstly, why is the local function inside of CharcterAppearanceLoaded? That’s just going to recreate it everything time a characterloads, I think it’s better you put that after local lvl = {}

Another thing is why is the loop inside of a loop that goes through all the players when a specific characterloads?

I was running out of ideas when I made that, but I’ll put the characterappearanceloaded after lvl.

Also what are you doing in

char.Humanoid.Died:Connect(function(hum)
	wait(3)
	player:LoadCharacter()
end)

Are you trying to do a fast respawn?

I don’t know if changing ; to , made a difference since it still switches to the next glove model when you level up.

I think they are using character auto respawn on off

Did you even check the errors? That should give you an error i would believe

I just wanted to change the respawn time to make it a little faster. I was probably going to change it when I got some other idea.

If it errored I don’t think it would’ve even placed gloves on the players in the first place since it’s directly above the rest of the code so it wouldn’t even put gloves on

I was hoping to get an error so I could hopefully fix this problem easier, but I didn’t get anything.

No output either? With all the prints?

Yes of course it printed in the output.

There’s a property in Players that allows you to lower the RespawnTime so that is not needed

Maybe try this

local bg = game.ReplicatedStorage.BG
local plr = game:GetService("Players")
local lvl = {}

local function CloneFunction(nxtGlove,char)
	local rHand = char:FindFirstChild("RightHand")
	local lHand = char:FindFirstChild("LeftHand")
	local gClone = nxtGlove:Clone()
	local g1Clone = gClone.RightGlove
	local g2Clone = gClone.LeftGlove
	local g1c_Weld = gClone.RightGlove.WeldConstraint
	local g2c_Weld = gClone.LeftGlove.WeldConstraint
	wait(0.3)
	gClone.Parent = char
	g1Clone.CFrame = char.RightHand.CFrame * CFrame.Angles(0,0,0) * CFrame.new(0,.169,0)
	g2Clone.CFrame = char.LeftHand.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0,.169,0)
	g1c_Weld.Part1 = char:FindFirstChild("RightHand")
	g2c_Weld.Part1 = char:FindFirstChild("LeftHand")
	g1Clone.CFrame = char.RightHand.CFrame * CFrame.Angles(0,0,0) * CFrame.new(0,.169,0)
	g2Clone.CFrame = char.LeftHand.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0,.169,0)
	g1Clone.CanCollide = false
	g2Clone.CanCollide = false
end

lvl = {
	bg.BaseGloves,
	bg.BaseGloves2
}

plr.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(char)		
		for i, v in ipairs(lvl) do
			if v.TypeVal.Value == player.gloveLVL.Value then
				CloneFunction(v,char)
				print(v)
				print(i,v)
			end
		end
	end)
end)

If you’re not changign anything i nthe gloves table you don’t need to put in CharacterAppearanceLoaded either

edit: I removed v.TypeVal.Parent and made it v because v.TypeVal.Parent is the same as v

Ok I’ll give this a try thanks.

Tell me if anything goes wrong!

It worked, but when I changed the respawn time in player it just reverted back to only cloning the model to one player again.

Hmm, maybe trying adding back the functions for death and 3 second respawn

local bg = game.ReplicatedStorage.BG
local plr = game:GetService("Players")
local lvl = {}

local function CloneFunction(nxtGlove,char)
	local rHand = char:FindFirstChild("RightHand")
	local lHand = char:FindFirstChild("LeftHand")
	local gClone = nxtGlove:Clone()
	local g1Clone = gClone.RightGlove
	local g2Clone = gClone.LeftGlove
	local g1c_Weld = gClone.RightGlove.WeldConstraint
	local g2c_Weld = gClone.LeftGlove.WeldConstraint
	wait(0.3)
	gClone.Parent = char
	g1Clone.CFrame = char.RightHand.CFrame * CFrame.Angles(0,0,0) * CFrame.new(0,.169,0)
	g2Clone.CFrame = char.LeftHand.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0,.169,0)
	g1c_Weld.Part1 = char:FindFirstChild("RightHand")
	g2c_Weld.Part1 = char:FindFirstChild("LeftHand")
	g1Clone.CFrame = char.RightHand.CFrame * CFrame.Angles(0,0,0) * CFrame.new(0,.169,0)
	g2Clone.CFrame = char.LeftHand.CFrame * CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0,.169,0)
	g1Clone.CanCollide = false
	g2Clone.CanCollide = false
end

lvl = {
	bg.BaseGloves,
	bg.BaseGloves2
}

plr.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(char)		
		for i, v in ipairs(lvl) do
			if v.TypeVal.Value == player.gloveLVL.Value then
				CloneFunction(v.TypeVal.Parent,char)
				print(v.TypeVal.Parent)
				print(i,v)
			end
		end
		
		char.Humanoid.Died:Connect(function(hum)
			wait(3)
			player:LoadCharacter()
		end)
	end)
end)

It sort of works now. It’s just cloning twice for the other player since I can see the models merging.