Im making a lightsaber system and i was wondering about loading animation onto the other player

Would i just do a normal Loadanimation on the players Humanoid?

local Part = --- Local
local Animation = --- Local

Part.Touched:Connect(function()
    if Hit.Parent:FindFirstChild("Humanoid") then
        Hit.Parent.Humanoid.Animator:LoadAnimation(Animation)
    end
end)

Is that all i would do?

In ur .Touched function, “Hit” will return as nil, you have to put “Hit” in the parantheses like this:

Part.Touched:Connect(function(Hit)

Now, Hit will return as the player who touched the part.
That’s not all, though. We still have to get the player’s character then humanoid:

Part.Touched:Connect(function(Hit)
    if Hit.Character:FindFirstChild("Humanoid") then
        Hit.Character.Humanoid.Animator:LoadAnimation(Animation)
    end
end

This function should work.

I messed up because i quickly made it in VSC, But last time i tried the animation it didnt load on them and it broke all other functions.

Oops.

Part.Touched:Connect(function(Hit)
    if Hit.Character:FindFirstChild("Humanoid") then
        Hit.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(Animation)
    end
end

Try this.

This is my current script.

Blade.Touched:Connect(function(Hit)
     
    if not DataFolder.Attacking.Value == true then return end
    
    if Hit.Parent:FindFirstChild("Humanoid") then

        local head = Hit.Parent.Head
        local headPos = Hit.Parent.Head.Position
        local ToolPos = Tool:WaitForChild("Hilt").Blade.Position
        local left = (head.CFrame*CFrame.Angles(0, math.rad(Distance ), 0)) * CFrame.new(0, 0, -0.1)
        local right = (head.CFrame*CFrame.Angles(0, math.rad(-Distance ), 0)) * CFrame.new(0, 0, -0.1)
        local fartherLeft = (head.CFrame*CFrame.Angles(0, math.rad(Distance + 0.1), 0)) * CFrame.new(0, 0, -0.1)
        local fartherRight = (head.CFrame*CFrame.Angles(0, math.rad(-Distance - 0.1), 0)) * CFrame.new(0, 0, -0.1)
        local isInsideAngle = (ToolPos - left.p).Magnitude < (ToolPos - fartherLeft.p).Magnitude and (ToolPos - right.p).Magnitude < (ToolPos - fartherRight.p).Magnitude 
        local OtherBlade = Hit.Parent:WaitForChild("Lightsaber").Hilt.Blade or Hit.Parent:WaitForChild("Backhand Lightsaber").Hilt.Blade
        local Animator = Hit.Parent.Humanoid:FindFirstChild("Animator")

        if isInsideAngle and Hit.Parent.Data.Blocking.Value == true then
            if DMGDebounce == false then
                DMGDebounce = true
                --- This is where i placed the LoadAnimation before but all it did was break their functions and animations
                Blade.Clash:Play()
                OtherBlade.ClashEffects.ClashLight.Enabled = true
                OtherBlade.ClashEffects.ClashSparks.Enabled = true
                wait(0.1)
                OtherBlade.ClashEffects.ClashLight.Enabled = false
                OtherBlade.ClashEffects.ClashSparks.Enabled = false
                wait(0.4)
                DMGDebounce = false
            end
        else
            if DMGDebounce == false then
                DMGDebounce = true
                Hit.Parent.Humanoid:TakeDamage(DataFolder.Dmg.Value)
                Blade["Hit" .. math.random(1,4)]:Play()
                wait(0.4)
                DMGDebounce = false
            end
        end
    end
end)

Are you asking about an error or if it’s just a good way to load animations? if you’re asking about loading, I think this is pretty solid, you can just load in the animations directly from humanoid/animator upon character’s creation, but I think this is better.

1 Like

Loading into the Humanoid Is Deprecated, I was just wondering if i was loading it in correctly, but i am im gonna look into other things that could be breaking my functions.

You could check if it’s being loaded using print(), and sorry about the deprecated method, I didn’t heard about it :sweat_smile:

I mean it loads, but it just breaks everything after.

you need to play a loaded animation

Animator:LoadAnimation(animation):Play()
1 Like

I have Played the loaded animation before.

local AnimationTrack = Animator:LoadAnimation(Animation)
AnimationTrack:Play()

Is your provided script a local or server script?