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

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

 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?

1 comment

0

What shows in output?

1 answer

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)

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