I’m making it so when you press a button it changes your character but when i change back to my original it moves the original to where i moved my previous character
game.ReplicatedStorage.SetCharacter.OnServerEvent:Connect(function(plr, name)
local oldModel = plr.Character
local newModel = game.ReplicatedStorage.Characters[name]:Clone()
local oldCFrame = oldModel:GetPrimaryPartCFrame()
newModel.Name = plr.Name
plr.Character = newModel
newModel.Parent = workspace
newModel:SetPrimaryPartCFrame(oldCFrame)
if not oldModel:FindFirstChild("NotActual") then
oldModel.Parent = game.ReplicatedStorage.PlayerModels
else
oldModel:Destroy()
end
end)
game.ReplicatedStorage.ChangeBack.OnServerEvent:Connect(function(plr)
local oldModel = plr.Character
local newModel = game.ReplicatedStorage.PlayerModels[plr.Name]
local oldCFrame = oldModel:GetPrimaryPartCFrame()
plr.Character = newModel
newModel.Parent = workspace -- [1] this follows current character loading behavior
local oldSpeed = newModel.Humanoid.WalkSpeed
newModel.Humanoid.WalkSpeed = 0
wait(1)
newModel.Humanoid.WalkSpeed = oldSpeed
oldModel:Destroy()
newModel:SetPrimaryPartCFrame(oldCFrame)
end)
Any help would be appreciated.