Moving Local Parts

So I had a lot of moving parts within my game and I was recently told it would be less stressful for the server if I moved them into the client, I’ve never really played around with this type of thing before but I did it by putting my moving parts in ReplicatedStorage and having a LocalScript inside StarterPlayerScript clone and parent them into Workspace(Is this the right way?).

I’ve had a problem when it comes to the scripts inside those parts that would make them move, they stopped working, I switched them to LocalScript and they also didn’t work. What is the issue?

1 Like

Just move them with a local script. No need to clone them.

2 Likes

Ahh yes I see!

I’ve probably worded it quite awkwardly now looking back but the script inside those parts would make the parts move in the world, like a platform moving from one place to another, this script doesn’t work when I parent the part into Workspace from ReplicatedStorage. What could be the problem there?

2 Likes

Create a LocalScript where LocalScripts will run (for example, in StarterPlayerScripts or StarterGui). Then, make the code to move the parts there.

1 Like

LocalScripts do not replicate to other clients (client == player, local script only runs on the client)
Server (normal) Scripts are replicated to all players

This means, if you Create, Edit or Delete a Part on the client - only your client will see the change - it doesn’t replicate to other players
Roblox Client-Server Model
Network Ownership (roblox.com)

To get around this - you need to set the NetworkOwnership of the part to the player. That way changes to the part will replicate.

--ServerScript
workspace.Part:SetNetworkOwner( player ) -- you'll probably need to either create a remote function or something to set this dynamically but that's a different issue.

Also, I’m not 100% sure on this but I believe LocalScripts only run in player associated objects, such as the Player, Backpack, PlayerGui, Character. This might have changed since but putting a LocalScript in a part I don’t believe runs the code.

3 Likes

Have those server scripts which are inside of the parts initially disabled. When the parts are moved to the workspace by the local script simply enable those scripts so that they can execute.

local replstorage = game:GetService("ReplicatedStorage")
local parts = replstorage:GetChildren()

for i, v in pairs(parts) do
	v.Parent = workspace
	for i, val in pairs(v) do
		if val:IsA("Script") then
			val.Disabled = false
		end
	end
end
1 Like