PlayerScripts - Scripts Replicated From Server Not Behaving Correctly

The Issue:
When a player’s character is created again from death, the user’s PlayerScripts removes scripts that were initially replicated from the server. What I mean by this is the following:

  • Place a LocalScript into a player’s PlayerGui on the server-side.
  • Within that LocalScript re-parent the script to PlayerScripts, on the client-side.
  • When the character respawns, this LocalScript gets destroyed for some reason.

Why I Need This:
I have the server deciding on appropriate scripts to send to the client from a library. As such, I’d like this to be done during run-time for simplicity in my use case.

Behaviour I Expect:
Scripts inside of PlayerScripts should not be removed when the player’s character respawns. This is understandable behaviour for CharacterScripts, but not PlayerScripts however.

Reproduction:
ReplicationTest.rbxl (15.2 KB)

  1. Read over the scripts inside of ServerScriptService to gain a better understanding of what is going on.
  2. Launch play-solo.
  3. If you look in your PlayerScripts, the LocalScript from the server is there.
  4. Set your character’s humanoid health to 0.
  5. The LocalScript inside of your PlayerScripts has been destroyed.

Hi, yeah this didn’t sound completely right to me, so I checked it out.
It looks like this isn’t directly related to PlayerScripts per se.

It appears what’s happening is that a reference to the LocalScript that was previously
parented to the PlayerGui is being tracked and cleaned-up, so I’m not sure if it’s
really a bug. I modified your LocalScript to use a clone instead, and it stayed on respawn:

local PLAYERS = game:GetService("Players")

wait()
if script.Parent.Name ~= "PlayerScripts"  then
	newscr = script:Clone()
	newscr.Parent = PLAYERS.LocalPlayer.PlayerScripts
end
-- script.Parent = PLAYERS.LocalPlayer.PlayerScripts

2 Likes

Thank you for the workaround.

If it is what you’re saying, then personally, I would actually class it as a bug. Upon the script leaving PlayerGui, the script should stop being tracked for cleanup.