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
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