In a simulator I am creating, each player will have a range to fire their cannon down. When they leave, I’m planning on moving the range into ReplicatedStorage to despawn it. As developing with everything already in ReplicatedStorage is a pain, I am leaving everything outside ReplicatedStorage to immediately be moved into ReplicatedStorage once the server loads. Then, once the player joins, one of the ranges will be moved back into the workspace. All of this happens within tenths of a second.
Problem
When I move a part into ReplicatedStorage, then out of Replicated storage using the PlayerAdded event, changes the server makes to the part no longer replicate to the client.
Here is the code, I added print commands to make sure everything runs in the proper order:
Here are a few things I have tried (and failed ) to gain an understanding:
I have verified that on the server the transparency is 0
Adding wait() before print("2") resolved the issue, and the transparency of the part changes to 1 on the client as it should. I still want to know what is going on, as I don’t know if this is a reliable fix.
It doesn’t matter if I put workspace.Part.Parent=game.ReplicatedStorage before or after I connect to the PlayerAdded event.
game.ReplicatedStorage.Part.Parent = workspace must be inside the PlayerAdded event in order for the bug to work. I tried changing it to a touch event, then touching the part after a few seconds, and the bug did not occur. If I immediately put the part into ReplicatedStorage and take it out, without having the PlayerAdded event the bug will not happen.
Having workspace.Part.Transparency = 0 is not necessary for the bug to happen. After moving the part into and out of replicated storage, most changes on the server do not replicate to the client.
If the part is anchored, then movement and position changes made on the server do not show up on the client. Appearance changes such as transparency, material, and color do still show up regardless of if the part is anchored or not.
I tested with the script inside Workspace and ServerScriptService and the result was the same.
What on Earth is going on?!?!
Thanks for any help!
ReplicatedStorage and all of its descendants are cloned/seen by the client. ServerStorage and all its descendants inside it is securely only seen/recognized by server-scripts.
This fixed it! I’m not going to mark it as the solution because I still want to know what was causing the bug in my original post. I’m also going to utilize ServerStorage more so I can have more security.
ReplicatedStorage is for assets you need both the server and client to have access to. As your script is on the server, moving the part it into workspace will cause it to be replicated to the client (although the client can’t access it whilst it is in ServerStorage). For the purposes of your scenario, the client doesn’t need to have access to the part whilst not in workspace. Hopefully this clears it up for you, let me know if you need further clarification!
I definitely understand that part, but what is confusing is in my scenario the part was moved out of ReplicatedStorage, then the part would stop updating on the client after a change on the server, even though it is in the workspace. I think this is more of a bug, so I might post it in the bugs forum.
If I had to make a guess, I think when I immediately move the part to ReplicatedStorage, it takes time to replicate to the clients. I think I then move it back to workspace with the PlayerAdded event before it has completed replicating to the client, causing this bug. I think this is true because if I add wait() before moving the object in the PlayerAdded event, everything work fine. I think the best solution was to use SeverStorage.