Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to fix an issue with Humanoid when it is not a descendant of Workspace?

Asked by 4 years ago
Edited 4 years ago

--Get the player

local character = Players.LocalPlayer.Character

if not character then

character = Players.LocalPlayer.CharacterAdded:Wait()

print("Waited")

end

character.Parent = workspace

local humanoid = character:WaitForChild("Humanoid")

repeat

wait()

print(character:IsDescendantOf(game), character.Parent)

if not character:IsDescendantOf(game) then

    character.Parent = workspace

end

until humanoid:IsDescendantOf(game)

-- Create new 'Animation' instance

local hitAnimation = Instance.new("Animation")

-- Set its 'AnimationId' to the corresponding animation asset ID

hitAnimation.AnimationId = "rbxassetid://4704497461"

-- Load animation onto the humanoid

local hitAnimationTrack = humanoid:LoadAnimation(hitAnimation)

Whenever I reset a character, there will be a error when loading an animation, and it is because the character, or humanoid is not a descendant of game. I have already looked at quite a few stuff on this topic, but I don't think they work. Definitely not the one where you just wait, because it does not set any parent. Setting the parent, like in the script above, gives the error of infinite yield on right shoulder(the moving part) when animation is called(there is more code but this is the error part). Maybe I should ask how to fix infinite yield problem, or maybe there is another option. Thanks in advance. Also, this is a local script, in a weapon. Sorry if the way I copied my code is bad I don't know how to make it proper.

0
An Infinite Yield is a warning the compiler throws when attempting to declare or reference an variable or Instance that doesn’t exist. Due to this, the compiler yields (waits) until it does; a warning is raised for the exception that it’ll wait forever, thus: ‘Infinite Yield Possible’ Ziffixture 6913 — 4y

2 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago

The Character is replaced upon Player death. The basis of this, is to cleanup and reload the avatar if it was damaged or tampered with. This may seem unconventional, however, it can provide itself very useful in situations with exploiting to many different scenarios.

Fun Fact: You can refresh the character anytime if you believe it was damaged with Player:LoadCharacter

Since the Character is reset, it no longer corresponds to the one you declared, therefore, you’ll need to compensate, and get the character once again:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

--// Code

Player.CharacterAdded:Connect(function(newCharacter)
    Character = newCharacter
end)
Ad
Log in to vote
0
Answered by 4 years ago

THANKS FOR THE ADVICE!!!!

Well, the code I have right now is a bit different to your example, but it was mainly based on it. Thanks so much, other places I read didn't have this code, which is simple and helps. I think I had this issue for a long time. This has saved my time so much, for there are quite a few issues with my weapon, but this, I believe, was the main one.

Again, thanks for the advice!

Answer this question