--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.
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)
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!