player.Character is nil when player joins game

I’m making a jojo game and when a player joins I’m making it so that they spawn everyone’s stands on their client. The problem is when the player joins and I fire the stand summon, script player.Character is nil. To be clear, this script is spawning the stand on other players so that the stands can be client sided. In this script player is not nil but for some reason player.Character is. I’ve tried player.Character:Wait()
and WaitForChild() and checking if the game is loaded with game:IsLoaded() etc. How do I fix this?
Heres my server script:

game.Players.PlayerAdded:Connect(function(Player)
	FirstJoin[Player.Name] = true
	Player.CharacterAdded:Connect(function(Character)
		ContentProvider:PreloadAsync(Character:GetChildren()); --make sure player char is fully loaded before firing
		if FirstJoin[Player.Name] then --check if player just joined
			--spawn everyone else's stands
			FirstJoin[Player.Name] = false
			for i--[[player]], v--[[value]] in pairs(Active) do
				print("pairs running")
				if v then
					remote:FireClient(Player, i, true) --checks if each player has a stand active and if so 
					--tells the player who just spawned to create the stand for that person
				end
			end
		end
		for i, v in pairs(Active) do --play all the stand anims for everyone else's stands
			moveRemote:FireClient(Player, i, MoveState[i])
		end
		Character.Humanoid.Died:Connect(function() --despawn the stand of the player who died
			remote:FireAllClients(Player, false)
		end)
	end)
end)

here’s the summon local script:

Summon.OnClientEvent:Connect(function(player, isActive)
	if not game:IsLoaded() then --attempt at waiting for game to load so player.Character works but it is already loaded so this makes no difference
		print("loading")
		game.Loaded:Wait()
	end
	local char = player.Character --THIS IS NIL WHEN SECOND PLAYER JOINS FOR SOME REASON (YES PLAYER EXIISTS, AND THE ACTUAL CHAR MODEL EXISTS, AND YES THE GAME IS LOADED) 
--also the player.Character is the player passed down from the remote event, the player who it is spawning the stand on
	local hrp = char.HumanoidRootPart
	if isActive == true then
-- summon stand etc etc
    end
end)
1 Like

The correct thing is player.CharacterAdded:Wait()

local char = player.Character or player.CharacterAdded:Wait()

3 Likes

The guy’s above thing is the solution, it always works.

1 Like

this isnt working. does it only work on server?

1 Like

No, it works for both client and server scripts.

1 Like
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character.PrimaryPart

while not character or not hrp do
    character = player.Character
    hrp = character.PrimaryPart
end
1 Like

still no. It says “attempt to index nil with ‘Wait’”

Are you sure that “player” is a player? That’s the only reason I could think that would cause that error.

I believe so. The only thing I could think of is that I am storing whether each player has a stand active in a table on the sever and then when I player joins the game accessing that table and sending the data through to the client. Is it a problem that I am technically passing the name of the player but not the actual value of the player? (Im not that good at lua so idk if this is a problem). If you look in my server script im just using a pairs loop to read the table and fire the client accordingly. If this is a problem how would I fix it?

is this script in a client or server?

this can be solved with some nested functions:

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
-- your code here.

--dummy code, delete this.
while task.wait(.1) do
character:Clone()
end

end)
end)