Animations not working in tools

I scripted the animation to work when an event comes, and I also grouped the animation IDs to make it work in group games, but it still doesn’t work.

All logs are displayed normally

animation IDs: rbxassetid://80661795158891

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local eventClean = ReplicatedStorage:WaitForChild("eventclean")

eventClean.OnServerEvent:Connect(function(player, spill)
	print("이벤트가 들어옴")
	local character = player.Character
	if not character then return end

	local tool = script.Parent  -- tool은 이 스크립트가 속한 부모인 툴입니다.

	local humanoid = character:FindFirstChildOfClass("Humanoid")
	local animation = tool:FindFirstChild("Animation")

	-- 애니메이션 객체가 있고, Animator도 존재하는지 확인
	print("애니메이션 로드 시작")
	local animationTrack = humanoid:LoadAnimation(animation)
	print(animationTrack)
	print(animation)
	animationTrack:Play()

	-- 3초 후에 애니메이션 정지
	task.delay(3, function()
		if animationTrack then
			animationTrack:Stop()
		end
	end)
end)
1 Like

Do not use animations in Humanoid, instead Humanoid has a child called AnimationController

Also try to pre-load the animations using PreloadAsync from the ContentProvider service.

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ContentProvider = game:GetService("ContentProvider")

local eventClean = ReplicatedStorage:WaitForChild("eventclean")
local player = Players.LocalPlayer

eventClean.OnClientEvent:Connect(function(spill)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	if not humanoid then
		warn("Humanoid not found")
		return
	end

	-- Use AnimationController instead of Animator
	local animationController = humanoid:FindFirstChildOfClass("AnimationController")

	if not animationController then
		warn("AnimationController not found")
		return
	end
	local tool = script.Parent  -- tool은 이 스크립트가 속한 부모인 툴입니다.

	-- Create the animation instance
	local anim = tool:FindFirstChild("Animation")

	-- Preload the animation using PreloadAsync
	ContentProvider:PreloadAsync({anim})

	-- Load and play the animation
	local track = animationController:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Action
	track:Play()

	-- Stop the animation after 3 seconds
	task.delay(3, function()
		if track then
			track:Stop()
			track:Destroy()
		end
	end)
end)

not working

1 Like

try to remove this piece of code^^ , and see what happens

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ContentProvider = game:GetService("ContentProvider")

local eventClean = ReplicatedStorage:WaitForChild("eventclean")
local player = Players.LocalPlayer

eventClean.OnClientEvent:Connect(function(spill)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	if not humanoid then
		warn("Humanoid not found")
		return
	end

	-- Use AnimationController instead of Animator
	local animationController = humanoid:FindFirstChildOfClass("AnimationController")

	if not animationController then
		warn("AnimationController not found")
		return
	end
	local tool = script.Parent  -- tool은 이 스크립트가 속한 부모인 툴입니다.

	-- Create the animation instance
	local anim = tool:FindFirstChild("Animation")

	-- Preload the animation using PreloadAsync
	ContentProvider:PreloadAsync({anim})

	-- Load and play the animation
	local track = animationController:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Action
	track:Play()

	
end)

not working ^^

1 Like

Use this script ^^ , and remove the Stop animation script

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local eventClean = ReplicatedStorage:WaitForChild("eventclean")
local player = Players.LocalPlayer

eventClean.OnClientEvent:Connect(function(spill)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	local animator = humanoid:FindFirstChildOfClass("Animator")
	
	local tool = script.Parent
	
	local animation = tool:FindFirstChild("Animation")
	-- 애니메이션 인스턴스 만들기
	local animationTrack = humanoid:LoadAnimation(animation)

	-- 애니메이션 로드 및 재생
	print(animationTrack)
	print(animation)
	animationTrack:Play()
end)

not working…

1 Like

Is this a local script?

if so, try it in a script

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local eventClean = ReplicatedStorage:WaitForChild("eventclean")

eventClean.OnClientEvent:Connect(function(player, spill)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	local animator = humanoid:FindFirstChildOfClass("Animator")

	local tool = script.Parent

	local animation = tool:FindFirstChild("Animation")
	-- 애니메이션 인스턴스 만들기
	local animationTrack = humanoid:LoadAnimation(animation)

	-- 애니메이션 로드 및 재생
	print(animationTrack)
	print(animation)
	animationTrack:Play()
end)

This?

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local eventClean = ReplicatedStorage:WaitForChild("eventclean")

eventClean.OnClientEvent:Connect(function(player, spill)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	local animator = humanoid:FindFirstChildOfClass("Animator")

	local tool = script.Parent

	local animation = tool:FindFirstChild("Animation")
	-- 애니메이션 인스턴스 만들기
	local animationTrack = humanoid:LoadAnimation(animation)

	-- 애니메이션 로드 및 재생
	print(animationTrack)
	print(animation)
	animationTrack:Play()
end)

This not working

1 Like

I meant this:

    local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	local animator = humanoid:FindFirstChildOfClass("Animator")

	local tool = script.Parent

	local animation = tool:FindFirstChild("Animation")
	-- 애니메이션 인스턴스 만들기
	local animationTrack = humanoid:LoadAnimation(animation)

	-- 애니메이션 로드 및 재생
	print(animationTrack)
	print(animation)
	animationTrack:Play()

put it in a script, not a local script, just to test

1 Like

image

Does the remote event get called?
and Print(“event called!”) to check

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local SpillCleanedEvent = ReplicatedStorage:WaitForChild("SpillCleaned")

local CLEANER_TEAM_NAME = "Cleaner [청소부]"
local TARGET_GROUP_ID = 12475608
local TARGET_RANK = 222
local MOP_ANIMATION_ID = "http://www.roblox.com/asset/?id=126407570972225"

local eventClean = ReplicatedStorage:WaitForChild("eventclean") -- 서버로 이벤트를 보낼 이벤트


local function SetupSpill(spill)
	local prompt = spill:WaitForChild("ProximityPrompt")
	local lock = false

	prompt.Triggered:Connect(function()
		if lock then return end

		local character = player.Character or player.CharacterAdded:Wait()
		local tool = character:FindFirstChildOfClass("Tool")
		if not tool or tool.Name ~= "Mop" then
			return
		end

		local isCleaner = player.Team and player.Team.Name == CLEANER_TEAM_NAME
		local isInGroup = player:IsInGroup(TARGET_GROUP_ID) and player:GetRankInGroup(TARGET_GROUP_ID) == TARGET_RANK

		if isCleaner or isInGroup then
			lock = true
			-- Spill을 청소하는 요청을 서버로 보냄
			eventClean:FireServer(spill)
			print("요청 보냄")
			prompt.Enabled = false

			local character = player.Character or player.CharacterAdded:Wait()
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			local animator = humanoid and humanoid:FindFirstChildOfClass("Animator")
			local animationTrack

			if animator then
				local anim = Instance.new("Animation")
				anim.AnimationId = "http://www.roblox.com/Asset?ID=126407570972225" -- ✅ 이렇게 고쳐야 함
				animationTrack = animator:LoadAnimation(anim)
				animationTrack:Play()

				task.delay(3, function()
					if animationTrack then
						animationTrack:Stop()
					end
				end)
			end

			while spill and spill.Size.Magnitude > 0.2 do
				spill.Size -= Vector3.new(0.02, 0.02, 0.02)
				task.wait(0.01)
			end

			if spill then
				game.ReplicatedStorage.SpillCleaned:FireServer(player)
				spill:Destroy()
			end
		end
	end)
end

-- 처음부터 있는 것들 연결
for _, spill in ipairs(workspace.SpillData.GlobalSpills:GetChildren()) do
	SetupSpill(spill)
end

-- 새로 생기는 것들도 연결
workspace.SpillData.GlobalSpills.ChildAdded:Connect(function(spill)
	SetupSpill(spill)
end)

This is a local script, I call the event here and receive it there.

1 Like

Try and change:

anim.AnimationId = "http://www.roblox.com/Asset?ID=126407570972225"

to

anim.AnimationId = "rbxassetid://126407570972225"

AND add prints everywhere to debug;
add print in:

if animator then

and

task.delay(3, function()
1 Like

because roblox doesn’t use this type of format in animations:

anim.AnimationId = "http://www.roblox.com/Asset?ID=126407570972225"

it uses:

anim.AnimationId = "rbxassetid://126407570972225"

if this still doesn’t work, make sure that the event is called, and the humanoid is found

2 Likes

image

This…?

1 Like

But not working

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local eventClean = ReplicatedStorage:WaitForChild("eventclean")

eventClean.OnClientEvent:Connect(function(player, spill)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	local animator = humanoid:FindFirstChildOfClass("Animator")

	local tool = script.Parent

	local animation = tool:FindFirstChild("Animation")
	-- 애니메이션 인스턴스 만들기
	local animationTrack = humanoid:LoadAnimation(animation)

	-- 애니메이션 로드 및 재생
	print(animationTrack)
	print(animation)
	animationTrack:Play()

end)
1 Like

What does this print in logs? or it doesn’t print at all?

1 Like

– 애니메이션 로드 및 재생
print(animationTrack)
print(animation)

No logs appear

1 Like