LoadCharacter()'s cframe not working

Hello. I’m trying to load in the player’s character and the position they were before their character is reloaded.

The loaded character’s CFrame seems to go to the determined previous CFrame for about a split second, and then just teleports me into the void. No idea why this would happen.


There are no errors that print that relate to the problem, and there are no others scripts that could possibly cause this.

Here’s my script:

plr.CharacterAdded:Connect(function(Character)
		---------------------------------------------------------------------------------------------
		---------------------------------------------------------------------------------------------
		local Team = Character:FindFirstChild("Team")
		local Attacker = Character:FindFirstChild("Attacker")
		if Team then
			if plr.Team == game.Teams.Rebellion then
				Team.Value = "Rebellion"
			elseif plr.Team == game.Teams["Zeta Robotics"] then
				Team.Value = "Zeta"
			end
		end
		local TeamClone = Team:Clone()
		---------------------------------------------------------------------------------------------
		if GameEnabled == true then
			if plr.Character:FindFirstChild("Team").Value ~= "Lobby" then
				if loaded.Value == false then
					local NewModel
					local DefaultCharacter = plr.Character
					local OldCFrame = DefaultCharacter:GetPrimaryPartCFrame()
					if Character then
						local oldModel = plr.Character
						---------------------------------------------------------------------------------------------
						--LOADOUT SETUP
						if not plr.PlayerGui:FindFirstChild("Loadout") then
					--		script.Loadout:Clone().Parent = plr.PlayerGui
						end
						loaded.Value = true
						---------------------------------------------------------------------------------------------
						local CharacterCF = Character:FindFirstChild("HumanoidRootPart").Position
						--Setting new character
						NewModel = ReplicatedStorage.PlayerAssets.Characters:FindFirstChild(Team.Value .. "Character"):Clone()
						---------------------------------------------------------------------------------------------
						if plr.DisplayName ~= "" then
							NewModel:FindFirstChild("Humanoid").DisplayName = "" .. tostring(plr.DisplayName)
						else
							NewModel:FindFirstChild("Humanoid").DisplayName = "" .. tostring(plr.Name)
						end
						---------------------------------------------------------------------------------------------
						plr.Character = NewModel
						TeamClone.Parent = NewModel
						NewModel.Parent = workspace.NPCs
						NewModel:SetPrimaryPartCFrame(oldModel.PrimaryPart.CFrame)
						oldModel:Destroy()
						---------------------------------------------------------------------------------------------
					end
				end
			end
		end
	end)
1 Like