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

:Play() is not a valid member of animation?

Asked by
Galicate 106
6 years ago
Edited 6 years ago

its a simple line of code and I don't understand why its not working.

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local Ammo = script.Parent:WaitForChild("Ammo")
local HoldAnimation = script.Parent.HoldAnim
tool.Equipped:connect(function(mouse)
    print("Tool equipped!")

    mouse.Button1Down:connect(function()
        if Ammo.Value >= 1 then
        print("Mouse pressed!")
        Ammo.Value = Ammo.Value - 1
        HoldAnimation:Play()
        print(Ammo.Value)
        script.Parent.Handle.Fire:Play()
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

        local beam = Instance.new("Part", workspace)
        beam.BrickColor = BrickColor.new("Bright red")
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Transparency = 0.5
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false

        local distance = (tool.Handle.CFrame.p - position).magnitude
        beam.Size = Vector3.new(0.3, 0.3, distance)
        beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)


        game:GetService("Debris"):AddItem(beam, 0.1)

        if part then
            local humanoid = part.Parent:FindFirstChild("Humanoid")

            if not humanoid then
                humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
            end

            if humanoid then
                humanoid:TakeDamage(10)

            end
        end
        end
        end)
end)

local Player = game.Players.LocalPlayer
local action_reload = false
Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key)
    if(Key:lower() == "r") and Ammo.Value < 7 and action_reload == false then
        action_reload = true
        script.Parent.Handle.Reload:Play()
        wait(2)
        Ammo.Value = 7
        print(Ammo.Value)
        action_reload = false
    end
end)

it gives me and output that says 18:03:23.044 - Play is not a valid member of Animation

0
Can you show more of the script thanks! Mr_MilkysButler 47 — 6y
0
yea let me edit the post. Galicate 106 — 6y
1
Please send a screenshot of the explorer ok? Really appreciated. OfcPedroo 396 — 6y
0
Probably you made a typo or specified the wrong path. As I said there up, also send a link to a screenshot of the explorer so I can help you. OfcPedroo 396 — 6y
View all comments (6 more)
0
Like use cut tools of windows and select the explorer part. then go to prnt.sc and upload the photo, and pass me the link they will give you. OfcPedroo 396 — 6y
0
(snipping tool) not cut tools. OfcPedroo 396 — 6y
0
ok thx. OfcPedroo 396 — 6y
0
oh and is the script there? OfcPedroo 396 — 6y
0
Yea the script is in the localscript with no name Galicate 106 — 6y

3 answers

Log in to vote
1
Answered by 6 years ago

Okay so you need to load your animations into the humanoid using this function

local C = player.Character
local Hum = C:WaitForChild("Humanoid")
local PlayAnim = Hum:LoadAnimation(HoldAnimation)
PlayAnim:Play()

-- Hopefully this helped!

0
OMG TRUE, I didn't remember the pre-load thing OfcPedroo 396 — 6y
0
curses, sniped again. DropshipPilot 148 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

You're on the right track! But, in order to play an animation, you have to first Load it onto the Humanoid.

The function Humanoid:LoadAnimation() is how you get an animation on a humanoid, ready to play. This function returns the AnimationTrack object, which is what you use :Play() on.

Example codes: (These use the LocalPlayer as a way of finding your player humanoid, so don't try and use the example copy-paste in anything but a Localscript.)

humanoid = game.Players.LocalPlayer.Character.Humanoid
animTrack = humanoid:LoadAnimation(script.Parent.HoldAnim)

animTrack:Play()

or:

game.Players.Localplayer.Character.Humanoid:LoadAnimation(script.Parent.HoldAnim):Play()

Link to AnimTrack properties on the wiki. Try messing with Playbackspeed!

Hope this helped.

Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
6 years ago
Edited 6 years ago

Shoutout to @Mr_MilkysButler and @DropshitPilot's awesome ideas, try this:

game.Players.PlayerAdded:connect(function(player)
    repeat wait() until player.Character

    local humanoid = player.Character.Humanoid
    humanoid:LoadAnimation(HoldAnim)
    HoldAnim:Play()

end)

Answer this question