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

Animation script is broken and needs a freeze edit, anyone help?

Asked by 6 years ago
 local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=3818677"

mouse.KeyDown:connect(function(key)
    if key == "m" then 
        local playAnim = humanoid:LoadAnimation(anim)
        playAnim:Play()
    end
end)

I don't know what I've done wrong with this, It doesn't play the animation. Also, I don't know if this effects it but it's a group animation in a group place. If possible would you be able to add a freeze script that stops the player from moving while the animation is on?

0
What shows in output? eloiishot 47 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

It's probably a problem to do with waiting for the character. You should also use UserInputService instead of KeyDown:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=3818677"

local track

game:GetService("UserInputService").InputBegan:Connect(function(key,bool)
    if bool == false and key.KeyCode == Enum.KeyCode.M then

        if (not track) or (track.IsPlaying == false) then
            debounce = false
            humanoid.WalkSpeed = 0
            humanoid.JumpPower = 0
            track = humanoid:LoadAnimation(anim)
            track.Looped = true
            track:Play()
        else
            track:Stop()
            humanoid.WalkSpeed = 16
            humanoid.JumpPower = 50
        end

    end
end)
Ad

Answer this question