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

Hopperbin activated animation tool?

Asked by 7 years ago
Edited 7 years ago

So, I've created an animation tool in which activates once the hopperbin tool is selected. It runs fine in Studio, but once in-game I get the error "Animation is not a valid member of LocalScript" in the developer console. All of the animations are saved inside the script, and I don't think I've done anything wrong? Could just be a small mistake.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
animation = script.Parent.LocalScript.ShunStart
animation1 = script.Parent.LocalScript.Salute
animation2 = script.Parent.LocalScript.RightDress
animation3 = script.Parent.LocalScript.AtEaseLoop
animTrack = nil

script.Parent.Selected:connect(function(Player)

    Mouse.KeyDown:connect(function(key)
        if key == "q" then
            for _,v in pairs(Player.Character:FindFirstChild("Humanoid"):GetPlayingAnimationTracks()) do v:Stop(0) end
            animTrack = Player.Character:FindFirstChild("Humanoid"):LoadAnimation(animation)
            animTrack:Play()
        end
    end)

    Mouse.KeyDown:connect(function(key)
        if key == "r" then
            for _,v in pairs(Player.Character:FindFirstChild("Humanoid"):GetPlayingAnimationTracks()) do v:Stop(0) end
            animTrack = Player.Character:FindFirstChild("Humanoid"):LoadAnimation(animation2)
            animTrack:Play()
        end
    end)

    Mouse.KeyDown:connect(function(key)
        if key == "t" then
            for _,v in pairs(Player.Character:FindFirstChild("Humanoid"):GetPlayingAnimationTracks()) do v:Stop(0) end
            animTrack = Player.Character:FindFirstChild("Humanoid"):LoadAnimation(animation3)
            animTrack:Play()
        end
    end)

    Mouse.KeyDown:connect(function(key)
        if key == "e" then
            for _,v in pairs(Player.Character:FindFirstChild("Humanoid"):GetPlayingAnimationTracks()) do v:Stop(0) end
            animTrack = Player.Character:FindFirstChild("Humanoid"):LoadAnimation(animation1)
            animTrack:Play()
            wait(3)
            animTrack:Stop()
            animTrack = Player.Character:FindFirstChild("Humanoid"):LoadAnimation(animation)
            animTrack:Play()
        end
    end)

    Mouse.KeyDown:connect(function(key)
        local Key = key:lower()
        if Key == "p" then
            for _,v in pairs(Player.Character:FindFirstChild("Humanoid"):GetPlayingAnimationTracks()) do v:Stop(0) end
        end
    end)

    script.Parent.Deselected:connect(function()
        for _,v in pairs(Player.Character:FindFirstChild("Humanoid"):GetPlayingAnimationTracks()) do v:Stop(0) return end
    end)
    end)

The tool's structure is:

Hopperbin

LocalScript

Animations

Any help on the matter is appreciated, but I just can't seem to get it working in-game.

1
Instead of individual functions, why not have one and just use an elseif? TheHospitalDev 1134 — 7y
0
This isn't the issue, I understand I'm a bit of a sloppy scripter. It works perfectly in studio, however in-game it states that the animations in LocalScript aren't a valid member of LocalScript. BritishActuaI 44 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Your problem being is that scripts do not take into account that all instances need to load first. When you join a game, and your script loads in, it will automatically start and not wait for all its children/any other instances to load

Studio does not need to load instances because it is all locally stored.

The best way to do so is like this:

lscript = script.Parent:WaitForChild("LocalScript")

animation = lscript:WaitForChild("ShunStart")
animation1 = lscript:WaitForChild("Salute")
animation2 = lscript:WaitForChild("RightDress")
animation3 = lscript:WaitForChild("AtEaseLoop")

The function WaitForChild() waits until it finds an instanced named inside the parenthesis then continues on with the script.

If there is no instance with the name that is inside the (), this script will wait infinitely, which will be said in the Developer Console

An alternative method is to add wait(3) to the start of your script, which is generally the time it takes for instances to load, but is not the best solution.

If you do not understand or have any queries, just ask.

0
Sorry for the late response. This was my first time working with animations, this fixed the issue I was having. Thank you very much. BritishActuaI 44 — 7y
0
Anytime User#13152 0 — 7y
Ad

Answer this question