Custom character

Hi!

I’m having some trouble with creating a custom character for my game. I already made a system to replace the current character (just putting a model called StarterCharacter inside of PlayerScripts and it automatically overrides the default) but now i’m trying to make my game more oop and make the character an object that I can easily swap out parts for. I am doing it the exact same way as before, but It doesn’t seem to work for some reason.

--calling main
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
--object module
local ship = require(script.Parent:WaitForChild("shipObject"))

local function initializePlayer(user)
--creating the player ship in game
    local newPlayer = ship:newPlayerShip(user)
    
end

initializePlayer(player)
--this is where I hold the information for each ship model
local shipFolder = game.ReplicatedStorage.shipModels

local shipInventory = {

--1
	["Galleon1"] = {
		["Model"] = shipFolder.StarterGalleon,
		["Name"] = "StarterCharacter",
	},

--2
	["Galleon2"] = {
		["Model"] = shipFolder.TestGalleon,
		["Name"] = "StarterCharacter"
	},
}

return shipInventory
--creating the player object

local replicatedStorage = game:GetService("ReplicatedStorage")
local shipInventory = require(replicatedStorage:WaitForChild("shipInventory"))

local shipObject = {}
local shipMethods = {}
local shipMetatable = {__index = shipMethods}

function shipObject:newPlayerShip(user)

    local playerShip = shipInventory["Galleon1"]
    local character = user.Character or user.CharacterAdded:Wait()
    local newship = {}

    --getting the ship model from inventory
    newship.Model = playerShip.Model:Clone()

    --inserting every model part inside of StarterCharacter
    for i, v in pairs(newship.Model:GetChildren())do
        v.Parent = game.StarterPlayer.StarterCharacter

    end

    setmetatable(newship, shipMetatable)

    return newship

end

return shipObject
--server side ship behavior
-- game.Players.CharacterAutoLoads = false

local function onCharachterAdded(character)
    local rootPart = character:WaitForChild("HumanoidRootPart")

    while not rootPart:IsDescendantOf(workspace) do
        wait()
    end

    rootPart:SetNetworkOwner(game.Players:GetPlayerFromCharacter(character))
end

local function onPlayerAdded(player)
    player.CharacterAdded:Connect(onCharachterAdded)
end

game.Players.PlayerAdded:Connect(onPlayerAdded)

Now, the code above does not error and it does insert all the ship parts inside of the ship model that I have in RS into it, but the player does not get copied into the game.

First image is before I start the game, and second image is after I start the game.
image

image

Now usually if I just were to put StarterCharacter with everything inside, it would work. But now this is whats going on. The player appears for a couple seconds with none of the parts but the humanoidRootPart and then deletes itself.

(gif)

Don’t exactly know how to go about this now, any help would be appreciated :slight_smile:

  1. It’s surprising to me that any character is loading, since I don’t see a call to LoadCharacter() anywhere in your script!
  2. Are you sure that CharacterAutoLoads is false? It looks to me like your character is dying (see next point) and respawning, which shouldn’t happen if CharacterAutoLoads==false.
  3. Are you overriding Animate, Health (and maybe Sound) in your StarterPlayer.StarterPlayerScripts? If not, your custom character will most likely die instantly.
  4. (main problem) You can’t change StarterCharacter from the client, it must happen on the server. It would be really bad if clients could change their own characters willy-nilly!

main solution

Roblox doesn’t support per-player StarterCharacters like you probably want.

It sounds like you don’t actually want any of the things that ROBLOX does for you with the Character. In that case, maybe don’t even use the Character at all and just insert a model into workspace, assign it to a player in your scripts, and act on that model as you wish (change the camera to follow it, have the input buttons move it, etc.)

1 Like

Hey!

I read over what you posted and made sense, I didn’t want to use roblox’s character system so I put a ship model into workspace once a player joins and assigned that player to the model and it worked! I’ll put the code below just incase somebody stumbles upon this post and has the same question as me :stuck_out_tongue:

--[[
    Description: 
        This script loads the custom ship into the player. 
    Author: 
        DataSigh
]]--

local shipLoading = {IsServer = true}

--Services
local RS = game:GetService("ReplicatedStorage")

--Disables auto respawns for players
game.Players.CharacterAutoLoads = false

--[[
    Function description:
        This function takes care of cloning a ship model from RS,
        whenever a player joins. and then loads it onto the player 
        model in workspace. It also makes sure the player spawns 
        in the right location.
]]--

local function onPlayerAdded(player)
    local ship = RS.shipModels.StarterGalleon:Clone()
    ship.Parent = workspace
    ship.Name = player.Name
    local rootPart = ship:WaitForChild("HumanoidRootPart")

    ship:SetPrimaryPartCFrame(CFrame.new(0,0,0))

    rootPart:SetNetworkOwner(player)
end

--Fires when a new player joins the game
game.Players.PlayerAdded:Connect(onPlayerAdded)

return shipLoading