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