Teleporting an NPC model from lighting and having it retain it's animation?

Hi everyone! I’m trying to teleport an NPC from Lighting to workspace, for a character-select type screen. However, whenever I teleport the NPC’s model, it loses the animation. I’ve tried disabling it, and then enabling it when it’s in workspace, but this doesn’t work. Even if it’s not disabled it still doesn’t work. How can I go about doing this? The animation is just a script that makes it act like a normal ROBLOX player.

First things first, putting things in game.Lighting is a very old method as nothing more suitable used to be available, however nowadays there is game.ReplicatedStorage for things that both the Client and Server need to be able to access.

The Animation script found in players is a LocalScript, which will only run when parented to specific locations. Are you perhaps using a LocalScript when you should be using a regular Script?

1 Like

I’m using a normal script. I was working on other things when I found that when I cloned another script, it didn’t work. The script is disabled until it’s properly parented to the head-- but it’s not printing anything. Could these two things be related? I’ll move it all from Lighting, though!

If a script isn’t Disabled and parented to (or a descendant of) workspace it should be running its content. I don’t really see a direct correlation in what you describe and a script not executing, could you post the code that’s doing the cloning and enabling of the script? Also have you checked whether the Script is enabled from the Properties window in studio after running your script to parent and enable it?

1 Like

Yeah! Okay, so this isn’t the main error because regardless of if the animation script was disabled or not it simply wouldn’t run. This one, however, is disabled in RepStorage until it’s parented to the clones head. It doesn’t report any errors but it also doesn’t print.

local person = LI.Test[char]:Clone() --LI = ReplicatedStorage
person.Parent = workspace.Holder --Holder is where I keep the character so we can easily delete it later
local BL = LI.Blink:Clone() -- Blink is the script I'm trying to clone and then enable
BL.Parent = person.Head
BL.Disabled = false

Here is the blink script. It’s a localscript but I did try it with a regular script to no avail.

local eyes = script.Parent:WaitForChild('Eyes')
print('on')

while true do
print('hi')
eyes.Texture = "rbxassetid://176207326"
wait(math.random(0.6,1.5))
eyes.Texture = "rbxassetid://176208715"
wait(0.05)
end

My first thought is WaitForChild is yielding indefinitely, are you sure ‘Eyes’ is actually a valid member (or becomes a valid member) of the script’s parent? Add a print line at the very top to confirm that it’s running instead of below the call to WaitForChild.

Eyes is definitely a member, and when I added a print line it didn’t work.

I’m super sorry if I’m being annoying or anything, I really appreciate you working with me!

Mhmm, needs more information. Excuse me if I’m echoing anything TaaRt has already told you.

Issues with this:

  • Using a legacy method of storing objects (use ReplicatedStorage or ServerStorage)
  • LocalScripts can’t run in Workspace

Lack information on:

  • What type of script you’re using to send this NPC over to the workspace and where the script is
  • Whether or not you’ve removed lines of code from the Animate script that reference the LocalPlayer
  • If the NPC is client-sided or server-sided; if server-sided, Animate needs to be converted to a script
  • Whether the script is running in the first place or not
  • If anything’s appearing in the console
  • What method of testing you’re using (Accurate Play Solo or not)
2 Likes

Okay! So!

I’m using a localscript in the player’s GUI to send the NPC to the workspace, it’s entirely local.
The animate script is made for NPCs, and it works fine if I don’t clone the NPC. (but this doesn’t work for what I need)
The NPC IS using a script, but it is client sided so I probably should put it in a localscript (?)
The script doesn’t appear to be running, which is the issue.
Nothing appears in console.
I’ve tried it in studio and actually going into the game- the results were the same.

Thank you!

Try switching the script type. If that doesn’t work, change it back.

When this kind of thing happens (as well as the fact that you said the console isn’t saying anything), I throw prints around my code to see where a print will run and where it will not, then address that specific line.


If not this, check the assembly of your character and see if there’s any differences between leaving one in the Workspace (server-sided) and what happens when you copy the NPC from a storage to the Workspace (client-sided model).

If none of this works, I resign - I have no solutions.

Just tried it all, unfortunately nothing worked. When I disabled it in the test one in workspace, and re-enabled it, it had the same results as when I copy it from RS to workspace. The animation isn’t exactly a game ending thing, as I’ve been able to just replace it with animations I made. But the blinking one is confusing me because I don’t see why it isn’t working? I’ve used scripts like it in the past so the fact it’s not working is strange to me.

1 Like

From the Wiki about LocalScripts;

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  1. A Player’s Backpack, such as a child of a Tool
  2. A Player’s Character model
  3. A Player’s PlayerGui
  4. A Player’s PlayerScripts
  5. The ReplicatedFirst service

Using a LocalScript in that player’s PlayerGui should be working, for this you parent it to game.Players[playername].PlayerGui or put it in StarterGui. A script in workspace won’t run client-sided unless it’s Disabled and set to Enabled from a particular Client.

I think I’m still a bit fuzzy on the details.

Where is this bit parented? Does it print if you add print statements?

local person = LI.Test[char]:Clone() --LI = ReplicatedStorage
person.Parent = workspace.Holder --Holder is where I keep the character so we can easily delete it later
local BL = LI.Blink:Clone() -- Blink is the script I'm trying to clone and then enable
BL.Parent = person.Head
BL.Disabled = false

So the Blink script itself is being cloned successfully to workspace.person.Head? It does run if you manually enable it from there? The Blink script should be a regular Script as well.

1 Like

The blink script is successfully cloned from RS to the NPC which is in workspace but created by the client. However if I put the blink script in an NPC in workspace and disable it and then enable it in a test play, it works as expected. However even if I try the same method with the cloned version-- it doesn’t work.

The script isn’t a local-script, and the code-snippet is from a localscript in the PlayerGui. It works fine, but the cloned script is the issue.

So manually cloning the Blink script from rep. storage to the NPC’s head gets it to execute when enabled, but the cloned version does not enable itself and does not execute when manually disabled and re-enabled either. It sounds like an existing issue with Accurate Play Solo. Can you disable it and see if the behavior changes?

2 Likes

This fixed it! Thank you so much!!

I tried creating a repro in Studio to attempt to reproduce this scenario. Let me know if it sounds similar to what you’re currently doing or if the results sound relatively similar.


Objects

ReplicatedStorage:
Dummy1, LocalScript Animate
Dummy2, Script Animate
Dummy3, LocalScript Animate
Dummy4, Script Animate

StarterGui (thus PlayerGui):
LocalScript Dummy1
LocalScript Dummy2

ServerScriptService:
Script Dummy3
Script Dummy4

All scripts had the following code:

local ok = game.ReplicatedStorage:WaitForChild(script.Name):Clone()
ok.Parent = workspace

Test Types & Results

Test Type Using APS Dummies Animated Dummies Idle
F5 & F6 No 2, 4 1, 3
F5 & F6 Yes 4 1, 2, 3
F7 No 4 1, 2, 3

I conclude that you’ll probably want to change your system altogether and animate the dummies in a different way. My only successful test is when the server clones a dummy and the Animate script is a server-script, thus being completely server-sided.

I know there must be a way to make this all client-sided, so you can locally clone NPCs and have their components work on the client, but I seem to be missing that.

A link to the repro I’m using is attached below. Feel free to experiment around.

CloningRepro.rbxl (28.3 KB)


As for the marked solution that was made before I finished typing: be sure that the supposedly now-working behavior also works in a live server, else you might be in a pinch again.

2 Likes

Thank you so much! Although the solution does work with a bit of tweaking I’ll keep this in mind!

1 Like