Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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??

1 comment

0

Where is this script located?

2 answers

✓ Accepted answer

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)

3 comments

0

@Azarth Can you define deprecated? I'm asking because I don't know what that means...

0

ROBLOX no longer supports it and it can break at any time.

0

Oh ok, thanks

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()

This discussion is preserved as it was. New answers, comments, and votes are closed.