Server Scripts not running in Workspace

-- NinjoOnline --

local getModel = {}

local replicatedStorage = game:GetService('ReplicatedStorage')

local classes = replicatedStorage:WaitForChild('Classes')

function loadIdleAnimation(humanoid)
	local animation = script['Idle']
if not animation then return end 

local animTrack = humanoid:LoadAnimation(animation)
	if not animTrack then return end

	animTrack.Looped = true
animTrack:Play()
end 

function getModel:Class(selected)
	local classFolder = classes:FindFirstChild(selected)
	if not classFolder then return end
	
	local classModel = classFolder:FindFirstChild('Armour')
	if not classModel then return end
	
	local clone = classModel:Clone()
	clone.Name = 'ClassDummy'
	
	if workspace:FindFirstChild('ClassDummy') then
		workspace.ClassDummy:Destroy()
	end
	
	for _, v in pairs(clone:GetChildren()) do
		if v:IsA('Part') or v:IsA('MeshPart') then
			v.Anchored = true
		end
	end
	
	clone.Parent = workspace
	
	local character = clone
	local humanoid = character.Humanoid

	loadIdleAnimation(humanoid)
end

return getModel

This is my module script. Running locally. When I put a print inside the animation function, it printed on every line.

But no animation was playing. Their is still Animator inside the Humanoid of the model

I am not sure if this i still the case but Looped animations do not replicating to new players. By this I mean an animation that is played in a loop will only replicate to the current ingame players after this new players will not see the animation play.

I am not sure how you are using this so cannot really help with what you can use to fix this.

Edit:-

The wasy way to check if this is the cause would be to just delay the function.

delay(5, loadIdleAnimation)

They’d have to have the second argument an anonymous function to pass the humanoid argument:

delay(5, function()
    loadIdleAnimation(humanoid)
end)

Im going by the code posted at the top?


Before and after. Nothing happening before, nothing happening after. It prints the ones when the function is fired

Just for good measure, could you use a different animation ID to check if it’s an issue with the animation itself?

Set the animation the same idle animation my character uses, still nothing

In that case, I’m not sure that I can help you further without access to a file containing the problem myself, sorry. Good luck! :grin:

I’m not sure if this helps, but have you tried setting your view to server? I don’t recall whether APS shows for both or only for the selected view. Maybe try setting it to server and see if it actually prints something.

Hi, interesting issue, got me interested in the thread. So, I noticed you didn’t debug to see if the animation was ever found. Just to be sure, you should change out this pile of code:

with:

local animation = script['Idle']
if not animation then error("something is wrong with 'animation'")

local animTrack = humanoid:LoadAnimation(animation)
if not animTrack then error("something is wrong with 'animTrack'")

Also, make sure the “script[‘idle’]” refers to an animation instance.
Tell me if something happens.

I had put prints after every line, and every line prints, up to the play. Putting in print(animTrack) after it has been found returns Idle as well

Hm… can you show me a screenshot of the relevant part of explorer?

This is where the module script and animation are located.

In your new ModuleScript code, after animTrack:Play(), could you add:

wait(5)
print(animTrack.IsPlaying)

I think maybe the issue is that you’re doing this from a module. While modules are neutral (not a serverscript and not a localscript) they won’t work in that way. Try to do this from a localscript.

That’s incorrect—ModuleScripts execute on the machine that requireed them. This is perfectly possible from a ModuleScript.

my bad then, but I’d still try it from a localscript

We know, from that, that the animation is definitely playing. There’s a couple of issues here that I can think of:

  • Is the character model rigged correctly? Could you provide a screenshot of the descendants of the model?
  • Is the animation playing, but for the wrong model? Could you identify which model the animation is playing on by, say, changing the head colour when the animation plays?

There’s everything inside it. Base dummy model, but I’ve used StickMasterLuke’s Wear Bundle plugin to get roblox bundles to replace the Mesh and TextureID of the default dummy to match the bundle