Character.parent is always nil

I’ve been working on a combat system lately and I noticed that after you die none of the animations work because the script is infinite looping because the character’s parent is always set to nil and it never gets changed to workspace so the script never continues I searched around the forum and I didnt seem to find any solution to this problem:

Code:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local debounce = false

local EssentialModules = game.ReplicatedStorage.EssentialModules
local rayhitboxes = require(EssentialModules.RaycastHitboxV3)

local status_module = require(game.ReplicatedStorage:FindFirstChild("Status_Module"))
local statusClient = status_module.new(player)



local combat_module = require(game.ReplicatedStorage:FindFirstChild("Combat_Module"))
local combatClient = combat_module.new(player)


print(character.Parent) -- Prints nil
warn("Player still is not loaded")

                             -- this passes             this doesnt pass                        this passes
repeat wait() until player:FindFirstChild("Loaded") and character.Parent ~= nil and character:FindFirstChild("Humanoid")

warn("Player finished loading") -- This doesnt print because character.Parent doesnt change from nil
print(character.Parent) -- Should print workspace but the code never continues

Any help is appreciated

Ok so I just added a wait(2) before line 1 and that seemed to fix it ? this whole error is confusing

What do you mean by “loading”, do you mean as in that everything within their avatar has loaded, including accessories and shirts/pants/t-shirts?

Anyways,
You can use Player.CharacterAppearanceLoaded

By “Loading” I mean the player has all the necessary values inside of him so the combat system can work properly

Then you should read my comment above, and use a repeat loop to wait for your custom values.

My problem is that I couldnt play animations because the character’s parent was still set to nil and not workspace, to further understand what I mean

Try using Player.CharacterAppearanceLoaded.

I had this same issue just now. The solution was to just spam char = player.Character until char stopped having a nil parent. In code:

local player = game.Players.LocalPlayer

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

while char.Parent == nil do

char = player.Character

wait()

end