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

This script is supposed to activate an animation when you click "C" but it doesn't, do you know why?

Asked by 6 years ago
local player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
    if (key == 'c') then
        local crawl = script.Parent.Humanoid:LoadAnimation(script.Crawl)
            if script.IsCrawling.Value == false then
                crawl:Play()
                script.IsCrawling.Value = true
            else
                crawl:Stop()
                script.IsCrawling.Value = false
            end
        end
    end)

In the output it says Animation Failed to Load. Is it a Roblox Asset Problem??

0
Where is this script located? Azarth 3141 — 6y

2 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Mouse input like you're trying to use is deprecated, refer to UserInputService.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
local UserInputService = game:GetService('UserInputService')

local crawl = script:WaitForChild('crawl')
crawl = humanoid:LoadAnimation(crawl)

UserInputService.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.C then 
    -- You can use IsPlaying to see if a sound is playing. 
        if crawl.IsPlaying then
            crawl:Stop()
        else
            crawl:Play()
        end
    end
end)
0
@Azarth Can you define deprecated? I'm asking because I don't know what that means... Thelegendofglitcher2 49 — 6y
0
ROBLOX no longer supports it and it can break at any time. Azarth 3141 — 6y
0
Oh ok, thanks Thelegendofglitcher2 49 — 6y
Ad
Log in to vote
0
Answered by
oSyM8V3N 429 Moderation Voter
6 years ago
Edited 6 years ago

Probably because u messed up with the Humanoid. Try this

For ex:

local p = game.Players.LocalPlayer

local crawl = p.Character.Humanoid:LoadAnimation(script.Crawl)
crawl:Play()

Answer this question