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.
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
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
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
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.
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.
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.