So, my main goal is to change the model, as well as its scripts to another one, only when spawning.
When im trying to copy components from reserved model with scripts into empty(only Humanoid instance) player character, the next is happening:
I have that custom spawn function in my selfwritten module:
return function(player:Player, targetModel:Model, atPos:Vector3, starterCharacterScripts:Folder, starterPlayerScripts:Folder)
if not game:GetService('RunService'):IsServer() then
error('Why are you doing that?')
end
player:LoadCharacter()
local characterModel = player.Character
local oldPrimary = characterModel.PrimaryPart
characterModel.PrimaryPart = oldPrimary
local humanoid:Humanoid = characterModel.Humanoid
for _,child:Instance in ipairs(targetModel:GetChildren()) do
local instanceCopy = child:Clone()
instanceCopy.Parent = characterModel
end
starterCharacterScripts:Clone().Parent = characterModel
starterPlayerScripts:Clone().Parent = player:WaitForChild('PlayerScripts')
characterModel:MoveTo(atPos)
return characterModel
end
What is the way to change the model and scripts (which will see this model as with Player.CharacterAdded()) can be the most effective for a particular player?
I am applying here. because I couldn’t find a solution to this problem on any other resource.
I will be very grateful for any help!