I have a button that when clicked changes the players character model. It works in studio, but when I play it online about 5 seconds after I change into the new body my player respawns like it gets reset or something. I don't understand what's happening or how to fix it. There are no errors in the output. I'll paste the scripts below.
workspace.spawnbox.button.ClickDetector.ClickEvent.OnServerEvent:connect(function(player) local character = game.ServerStorage.Models.P:Clone() character.Parent = workspace character.Name = player.Name character:MoveTo(Vector3.new(0,8,0)) player.Character = character game.ReplicatedStorage.Remotes.CharacterAdded:FireClient(player, character) local guis = game.ServerStorage.guis for i, v in ipairs (guis:GetChildren()) do v:Clone() v.Parent = player.PlayerGui end end)
local player = game.Players.LocalPlayer function onRemote(character) character.Animate.Disabled = false workspace.CurrentCamera.CameraSubject = character.Head end game.ReplicatedStorage.Remotes.CharacterAdded.OnClientEvent:connect(onRemote)