Server Scripts not running in Workspace

I’m trying to run animations on a Dummy model.

The model is stored in ReplicatedStorage. When I need it, I clone it and put the clone inside Workspace.

Problem arises when the script does not even run once it’s in the Workspace.

-- NinjoOnline --

print(1)

local character = script.Parent
local humanoid = character.Humanoid

function loadIdleAnimation()
	print(1)	
	local animation = script['Idle']
	print(1)
if not animation then return end 
	print(1)
local animTrack = humanoid:LoadAnimation(animation)
	if not animTrack then return end
	print(1)
	animTrack.Looped = true
animTrack:Play()
end 

loadIdleAnimation()

Doesn’t even print the top 1, so it’s not like it’s the function, it’s the entire script just not running. It is not Disabled either.

2 Likes

Is archivable set to true?
This is a regular script too, correct?

3 Likes

Why duplicate post?

I made a quick baseplate file roughly demonstrating the difference between Archivable true/false, which is what I believe is affecting your script. Here’s the baseplate file (13.1 KB)

or for convenience,

Here's the code, output and explorer
local Model = game:GetService'ReplicatedStorage':WaitForChild'Model'
local Script = Model:WaitForChild'Script'

wait(1)
print'Parenting model with Archivable set to true'
Model:Clone().Parent  = workspace

wait(1)
print'Parenting model with Archivable set to false'
Script.Archivable = false
Model:Clone().Parent = workspace

Output:

> Parenting model with Archivable set to true
> 1
> Parenting model with Archivable set to false

Explorer:
image

Happy birthday @vsnry :cake:

That’s quite peculiar.

Archivable is set to true

This is odd. Does the behaviour remain the same when you do this in an empty place?

Just testing it now in your place, with cloning a dummy with the animations

Now I’m really stumped.

It works in the empty place, but not in my place. Everything in my place is Archivable, the model is being cloned to Workspace. The script is inside the model as well

Did you copy and paste the exact same Script Instance from the other place?

No, because I have my cloning script setup in a special way:

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
end

This is what I use to get the model, and then parent it to workspace. Has to be like this as I have multiple classes and the point of this is to change the class in workspace to whatever class the player has selected

OK. I’m thinking that another Script may be causing the issue—could you finally check, while play-testing, if:

  • The Script is being parented to Workspace properly. Is it even there?
  • The Script’s BaseScript.Disabled property is still false after being parented to Workspace.

If you still can’t find the issue, could you provide me with a file in which the issue is present?

Script is definately there inside the model

Unfortunately, I can’t give out the project file because it contains too much work in it :confused:

EDIT And even clicking disable, and then re-enabling it while in game still does not print anything from the script.

Understandable—is there any way that you could replicate the problem with the relevant assets without the rest of the work for me to take a look at?

Could it have anything to do with the fact that I’m cloning it by the Client?

In your test place, it was cloned by a server script. This is being cloned by the Client (inside a ModuleScript, but running locally)

It has to be cloned locally though, as the model has to only be viewable by the client and each player will have different models loaded)

This is definitely the issue.

When you clone the Model on a client, the Script inside that Model (and the Model itself) will only exist on that client, not the server. As you probably know, Scripts only run server-side—in fact, the bytecode of Scripts aren’t even sent to the clients.

Taking a look at your original code, it seems like this could very well work in a LocalScript, which executes client-side. If you switch the type of script, does the place function as expected?

And, by the way, it wasn’t me who provided you with the test place. :stuck_out_tongue:

1 Like

I had tried it as a LocalScript originally.

Still getting nothing :frowning:

I was sure I was told last time that LocalScripts don’t run when inside the workspace or something? But ye, still nothing :confused:

You’re right; LocalScripts don’t run inside the Workspace unless they are parented to the local player’s character.

Could you slightly rework the code so that, the animation is handled in a LocalScript that’s inside the local player’s PlayerScripts? The contents of StarterPlayerScripts are parented to PlayerScripts when the local player first joins. If possible, I’d personally consider handling the animation directly from the ModuleScript.

Tried that before as well :confused:

Put it back inside the ModuleScript, and it prints everything, but it doesn’t actually play the animation at all

If the ModuleScript is running the on client and the Model has a Humanoid, you should be able to do the animating the same, more or less, as your original code, and this seems like the way to go. I suggest handling the animation directly from the ModuleScript and ensuring that you’re not making any mistakes that may cause the code to work incorrectly. If the Model doesn’t have a Humanoid you can use an AnimationController.