Why do animations work in studio but not in game?

Hey devs! I was wondering why my animations work when I test it in studio but then when I test in a Roblox game it doesn’t work only is meant to run on client aswell to stop mobs in tower defense getting buggy. Animations also don’t work for my other Devs while in studio so what’s the issue here? here’s animation script


local events = ReplicatedStorage:WaitForChild("Events")
local animateTowerEvent = events:WaitForChild("AnimateTower")

local function setAnimation(object, animName)
	local humanoid = object:WaitForChild("Humanoid")
	local animationsFolder = object:WaitForChild("Animations")
	
	
	if humanoid and animationsFolder then 
		local animationObject = animationsFolder:WaitForChild(animName)
		
		if animationObject then 
			local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)
			
			local playingTracks = animator:GetPlayingAnimationTracks()
			for i, track in pairs(playingTracks) do 
				if track.Name == animName then
					return track
				end
			end
			
			local animationTrack = animator:LoadAnimation(animationObject)
			return animationTrack
		end
	end
end

local function playAnimation(object, animName)
	local animationTrack = setAnimation(object, animName)
	
	if animationTrack then 
		animationTrack:Play()
	else 
		warn("Animation Track Does Not Exist")
		return
	end
end


workspace.Mobs.ChildAdded:Connect(function(object)
playAnimation(object, "Walk")
	end)
	workspace.Towers.ChildAdded:Connect(function(object)
	playAnimation(object, "Idle")
		end)

animateTowerEvent.OnClientEvent:Connect(function(tower, animName)
	playAnimation(tower, animName)
end)

Thanks any help appreciated

3 Likes

Hello, the issue could be that (if your working on a team create game or under a group, the owner of the game has to publish the animations. If your game is owned by a group, you have to upload them under the group instead. Hope this works.

7 Likes

Thank you so much I really appreciate this

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.