(REPOSTED) Character not loading?

(I reposted this because no one responded and I’m stuck)

This code is meant to load the character when they press play during a game, but it doesn’t :confused:

LoadCharacter function

function module.LoadCharacter(player)
	local gamePlayer = game.Players:FindFirstChild(player)
	if gamePlayer then gamePlayer:LoadCharacter() return gamePlayer.Character end
end

Teleport function

function module.teleportPlayer(playerName, teleportLocation)
	local gamePlayer = game.Players:FindFirstChild(playerName)
	if gamePlayer then
		local character = gamePlayer.Character or gamePlayer.CharacterAdded:Wait()
		local crawlScript = game.ReplicatedStorage.Scripts.CrawlScript:Clone()
		crawlScript.Parent = character
		crawlScript.Disabled = false
		character:WaitForChild("HumanoidRootPart").CFrame = teleportLocation.CFrame
		events:WaitForChild("toggleMainMenu"):FireClient(gamePlayer, false)
		events:WaitForChild("toggleGameGui"):FireClient(gamePlayer, true)
		module.AddModelToCollisionGroup(character)
	end
end

This works

function module.respawnAllPlayers()
	for i, player in pairs(game.Players:GetChildren()) do
		if not game.Workspace:FindFirstChild(player.Name) then
			module.LoadCharacter(player.Name)
		end
	end
end

This doesn’t

events:WaitForChild("joinGame").OnServerEvent:Connect(function(player)
	print(player.Name .. " has pressed play")
	-- BRAND NEW PLAYER
	if not roundInfo.DeadPlayers:FindFirstChild(player.Name) and not roundInfo.Players:FindFirstChild(player.Name) then
		if roundInfo.GameStatus.Value == "Game" and roundInfo.Countdown.Value > 0 then
			local character = game.Workspace:FindFirstChild(player.Name)
			if not character then
				character = module.LoadCharacter(player.Name)
			end
			events:WaitForChild("toggleMainMenu"):FireClient(player, false)
			events:WaitForChild("toggleGameGui"):FireClient(player, true)
			events:WaitForChild("resetCamera"):FireClient(player, character)
			module.teleportPlayer(player.Name, game.Workspace.GameAssets:WaitForChild("Map").PlayerSpawn)
			module.AddPlayerToRoundInfo(player)

PS Everything else works, just the character doesn’t load :confused:

People viewed it, but no one responded…
Probably meant that no one understood what was going wrong.

I don’t have a grip on programming so I don’t either.

Have patience and in the meanwhile, try to work on other aspects of your project.
Good luck!

1 Like

Thanks for your comment, but the issue is that my project is almost done, and this is my biggest issue at the moment, so I have to try to work it out. Thanks for your input though :slight_smile:

1 Like

I don’t understand, so the character doesn’t load at all the the events:WaitForChild(“joinGame”) part is broken because of it?

No, for some reason the code doesn’t load the character, even though it tries to teleport them and resets their camera, but the character doesn’t seem to spawn for some reason…

However, is it in the workspace (the character)?, by the way, this:

local character = game.Workspace:FindFirstChild(player.Name)
if not character then
	character = module.LoadCharacter(player.Name)
end

Is CharacterAutoLoad’s enabled?, what I’m trying to say is if a player joins the game and CharacterAutoLoad’s in disabled then if not Character would run but if it is enabled then it wouldn’t run.

The way your setting the character variable might be a problem too.

And does it ever get past if not character?, try adding a print statement. If it does then we’ll know where to fix.

Cant u literally do player:LoadCharacter()? or u can simply set humanoid health to 0 to kill them to make them respawn, whats the point of writing a whole module function for a line of code?

The player doesn’t load automatically, i need that so i can set their character to a custom one

It does get past the if not character part, but for some reason it doesn’t load :confused:

You’re setting it to a custom character? Well I’ve got 2 things for u:

  1. Make sure ur custom character is rigged
  2. Are there any methods of cleanly swapping character models from default rigs to custom character constructs? - #12 by PeZsmistic

No, the custom character code works fine, but when trying to load the player’s ordinary character, it doesn’t work

Oh, so you’re switching the character back? For that I would recommend cloning the players original character into repl storage and when switching back set the Character property of the player to the original character in repl storage. Also make sure to set the og char’s parent to workspace