Hello! So this fix is fairly simple! Let me explain it a little bit first.
The way I approach this is by using the PlayerAdded event! It's simple and easy too. Now the problem is how you have you function setup, so I will edit you code to make it compatible with the new code!
Below, is the framework for the new stuff!
function changeMe(player)
end
game.Players.PlayerAdded:connect(changeMe())
Now that we have the framework, let's continue with the explaination!
function changeMe(player)
local character = player.Character or player:WaitForChild("Character")
local humanoid = character.Humanoid or character:WaitForChild("Humanoid")
if (humanoid ~= nil) and debounce == false then
debounce = true
originals = character:GetChildren()
for _, object in pairs(originals) do
if object:IsA("CharacterMesh") then
object:Remove()
end
end
meshes = script:GetChildren()
for _, object in pairs(meshes) do
copy = object:Clone()
copy.Parent = character
end
end
wait()
debounce = false
end
game.Players.PlayerAdded:connect(changeMe())
I definitely changed A Lot of code, but I won't leave you stranded!
If you see, I changed you "for loops" to be MUCH more efficient! Now what they do specifically, is cycle through a table and return two things, the index and the table item! The , object are those two parameters, but since we don't need the index, I wrote mine as a garbage variable or "".
Here is also a link for more information on loops, including the one I used!
P.S. Don't copy my code and expect it to fully work! Skim over it to see if there are errors and if there are errors, please let me know!