Character Replaced then teleporting at random

can someone help me figure out why I keep getting teleported back to spawn? The script takes the players accessories and adds them to a custom character but I keep teleporting back to spawn at random

Blockquotelocal CharCmodule = {}
function CharCmodule.CharCreate(player)
local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
– Define the path to your custom character model in ReplicatedStorage or Workspace
local CustomCharacterModel = ReplicatedStorage:WaitForChild(“Elf”):Clone()
player.CharacterAdded:Connect(function(character)
– Remove the default character if it somehow loads
if character then
for _, child in ipairs(character:GetChildren()) do
if child:IsA(“Accessory”) then
child:clone().Parent = CustomCharacterModel
wait(0.1)
end
end
character:Destroy()
end
– Clone the custom character model
local newCharacter = CustomCharacterModel:Clone()
newCharacter.Name = player.Name – Name the character after the player
newCharacter.Parent = workspace – Parent it to the workspace
– Set the player’s character to the custom model
player.Character = newCharacter
– Position the character at a spawn location (optional)
local spawnLocation = workspace:FindFirstChild(“SpawnLocation”) – Replace with your actual spawn point
if spawnLocation and newCharacter.HumanoidRootPart then
newCharacter:SetPrimaryPartCFrame(spawnLocation.CFrame)
end
end)
– Force initial character load when player joins
player:LoadCharacter()
end
return CharCmodule

i haven’t a clue why but this is the script now and it’s not teleporting me

local CharCmodule = {}

function CharCmodule.CharCreate(player)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local CustomCharacterModel = ReplicatedStorage:WaitForChild(“Elf”)

local function createCustomCharacter(defaultChar)
	-- Clone custom character
	local newCharacter = CustomCharacterModel:Clone()
	newCharacter.Name = player.Name
	newCharacter.Parent = workspace
	player.Character = newCharacter

	-- Copy appearance (accessories, clothes, body colors)
	if defaultChar then
		for _, child in ipairs(defaultChar:GetChildren()) do
			if child:IsA("Accessory") 
				or child:IsA("Shirt") 
				or child:IsA("Pants") 
				or child:IsA("BodyColors") then
				child:Clone().Parent = newCharacter
			end
		end
	end

	-- Move to SpawnLocation if it exists
	local spawnLocation = workspace:FindFirstChild("SpawnLocation")
	if spawnLocation and newCharacter:FindFirstChild("HumanoidRootPart") then
		newCharacter:SetPrimaryPartCFrame(spawnLocation.CFrame + Vector3.new(0,5,0))
	end

	-- Remove the default character
	if defaultChar then
		defaultChar:Destroy()
	end
end

-- Run every time Roblox spawns a character
player.CharacterAdded:Connect(function(defaultChar)
	--task.wait(0.5) -- wait so accessories load in fully
	createCustomCharacter(defaultChar)
end)

end

return CharCmodule

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.