Why does the Character Gamepass make the Character not Respawn

Hello everyone so basically a gamepass makes it so that if they own it, it will give them their Roblox Character instead of the custom character spawn. This works but for some reason if the player is the custom spawn character so basically does not own the gamepass and dies, they never respawn and some admin has to use a respawn them command. But if they own it they respawn. Why is this? There are more scripts but this is the main:

local Players = game:GetService("Players")
local char = game:GetService("ServerStorage").StartChar
local gamePassID = 12191213

function onPlayerSpawned(player) 

	local hasPass = false

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)
	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))
		return
	end

	if not hasPass then
		player.CharacterAppearanceLoaded:Connect(function(plrChar)
			wait()
			local newChar = char:Clone()
			newChar.Parent = workspace
			newChar:MoveTo(plrChar:WaitForChild("HumanoidRootPart").Position)
			newChar.Name = player.Name
			player.Character = newChar
			print("Works")
			
			plrChar:Destroy()
			game:GetService("ReplicatedStorage").LoadAnims:FireClient(player, newChar)
		end)
	end
end

game.Players.PlayerAdded:Connect(onPlayerSpawned)
3 Likes

Hm yes but I want to do fix the script before doing small changes. Thanks for the tip!

1 Like

If anyone has an answer please answer!

1 Like

CharacterAppearanceLoaded only fires when Player.Character is successfully loaded. Your PlayerAdded event is only firing once (because the player only joins the game once.)

Try the following inside of the PlayerAdded event:

Player.CharacterAdded:Connect(function(Character)
-- custom character logic
end)
1 Like

Like this?

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local char = game:GetService("ServerStorage").StartChar
local gamePassID = 12191214

function onPlayerSpawned(player) 

	local hasPass = false

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)
	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))
		return
	end

	if not hasPass then

		Player.CharacterAdded:Connect(function(Character)
		player.CharacterAppearanceLoaded:Connect(function(plrChar)
			wait()
			local newChar = char:Clone()
			newChar.Parent = workspace
			newChar:MoveTo(plrChar:WaitForChild("HumanoidRootPart").Position)
			newChar.Name = player.Name
			player.Character = newChar
			print("Works")
			
			plrChar:Destroy()
			game:GetService("ReplicatedStorage").LoadAnims:FireClient(player, newChar)
		end)
	end
end

Player.CharacterAdded:Connect(function(Character)
1 Like

General disclaimer - this may error due to some syntax error (I typed this out as a reply.)

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local char = game:GetService("ServerStorage").StartChar
local gamePassID = 12191214

Players.PlayerAdded:Connect(function(player)
		local hasPass = false

		local success, message = pcall(function()
			hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
		end)
		if not success then
			warn("Error while checking if player has pass: " .. tostring(message))
			return
		end

	player.CharacterAdded:Connect(function(plrChar)
		if not hasPass then
			wait() -- this isnt really necessary
			local newChar = char:Clone()
			newChar.Parent = workspace
			newChar:MoveTo(plrChar:WaitForChild("HumanoidRootPart").Position)
			newChar.Name = player.Name
			player.Character = newChar
			print("Works")
			plrChar:Destroy()
			game:GetService("ReplicatedStorage").LoadAnims:FireClient(player, newChar)
		end
	end)
end)
1 Like

Yep it glitches the player in midair for some reason why is that? And it looks like it is stuck. I got the eror you forgot to add if not hasPass then But it still does that because I think you forgot to use this: player.CharacterAppearanceLoaded:Connect(function(plrChar) which causes it to never load the character. So how would I fix this?

Can you show me the error that occurs where I “forgot to add not HasPass?” I added it in the CharacterAdded event, it shouldn’t be saying it’s nil.

This is the problem. The function keeps cycling again and again which causes a glitch. That is why Works keep going on and on forever which glitches the player. Maybe the game.CharacterAdded is in the wrong place? Should it be inside the if statement?

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local char = game:GetService("ServerStorage").StartChar
local gamePassID = 3196348

function onPlayerSpawned(player) 

	local hasPass = false

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
	end)
	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))
		return
	end

	if not hasPass then
		Players.PlayerAdded:Connect(onPlayerSpawned)
		player.CharacterAdded:Connect(char)
		player.CharacterAppearanceLoaded:Connect(function(plrChar)
			plrChar:Destroy()
			wait()
			local newChar = char:Clone()
			newChar.Parent = workspace
			newChar.Name = player.Name
			player.Character = newChar
			print("Works")
				game:GetService("ReplicatedStorage").LoadAnims:FireClient(player, newChar)
				end)
	
	end
end
Players.PlayerAdded:Connect(onPlayerSpawned)
Players.CharacterAdded:Connect(char)

This script works. When you reset your character is okay but if they move and reset it does not work. Do you know why?

1 Like