i was making data save stuff and when i run this function providing the player and model to switch with, it brings up this error.
can someone explain whats going on here?
code:
local Swap = function(player,model)
if model == nil then return end
-- Things
local CurrentChar = player.Character
local char = model:Clone()
local savename = player.Name
local pos = player.Character.HumanoidRootPart.CFrame
local Health = game.ReplicatedStorage.Swap_Things.HealthBar:Clone()
local Inv = player.Backpack:Clone()
local TrollV = player:FindFirstChild("Trollge")
-- Set Char
TrollV.Value = model.Name
char.Name = savename -- error is here
player.Character:Destroy()
player.Character = char
char.Parent = workspace
char.HumanoidRootPart.CFrame = pos
Health.Parent = char
Health.Script.Enabled = true
for i,v in player.Backpack:GetChildren() do
v:Destroy()
end
for i,v in Inv:GetChildren() do
if v:HasTag("Weapon") then continue end
v.Parent = player.Backpack
end
Inv:Destroy()
end