Clone parts on Client Side

How can I make it so that parts that I clone on the client can be seen by the entire server while still being on the client side?

So right now in my game, I have a system where you click, your head gets cloned and that head is just part of you now until you sell. However, when there is a certain amount of heads that spawn, people in the server start to lag because the parts are cloned to the server.

What I want to find out is how can I still clone the head of the player that clicked locally and other people are still able to see it without affecting their performance?

(I know I have to use multiple RemoteEvents but I’m having trouble with the last client sided script)
Client > Server > Client --This last script

1 Like

What you’re trying to do sounds like using Network Ownership, which is generally discouraged because of vulnerability exploits
If you still wanna try, just create the part on the server, set its network owner to the player, and have that player manipulate the part in a localscript
https://developer.roblox.com/en-us/api-reference/function/BasePart/SetNetworkOwner

1 Like

Is there a different way of doing the same thing without Network Ownership to prevent exploits? If no, are there any ways to protect it from exploits?

It’s basically unavoidable; so long as the client is in charge of something, there’s going to be the risk of them doing unforeseen evils
The original method you described isn’t any better, the client can just hijack the remote to send modified information with malicious intent

I guess you have to just do everything on the server, even if it means causing lag, safety comes first :person_shrugging:

1 Like

Actually, it really just depends on the use case. Network ownership shouldn’t be used on any critical game mechanics, but for simpler processes like visual effects it should be fine, you’ll just have to implement a lot of security checks to make sure they can’t do anything bad like teleport blocks into other player’s face

1 Like

So before on a different post, someone suggested to use :FireAllClients and use that in a local script to display all the players cloned heads. Does that still require using Network Ownership?

It is essentially the same as Network Ownership in that it is equally vulnerable, you’re still giving the client power to control and manage objects that are seen by everyone

Make a system when the player clicks it fires a remote to the server, when the server receives the button press from the remote, fire to all clients a remote that will clone the head, that way the head will be on everyone’s client.

The last script is where you actually clone the head.

As I asked in a previous post, how exactly do I do that? I know how to send the remote to server, then the server sends a remote to the client again BUT I’m not sure how to clone the head onto the player that clicked locally and still make it show to everyone else.

I tried using :FireAllClients: but it didn’t work so do you have any suggestions?

Could you send me a place file of what you have done, it would make it easier to help you.

Sorry, I don’t really trust sending my entire place file. I can just send the parts of my scripts that send the remotes to each other.

Sending Client

UserInputService.InputBegan:Connect(function(input)
	if h.Value < ContainerSpace.Value then 
		if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
			event:FireServer()
		end
	end
end)

Server

event.OnServerEvent:Connect(function(player)
	PlayerEvent:FireAllClients()
end)

Cloning Client

event.OnClientEvent:Connect(function(player)
	local headFolder = char:WaitForChild("headContainer")
	local c = head:Clone()
	c.Parent = headFolder
end)

The problem is when you fire all clients your not specifying which player to clone the head to, your not sending the “player who the head should be cloned for” over to all clients from the server.

In the first script you should add the following:

local localPlayer = game.Players.LocalPlayer
local playerWhoHeadToClone = localPlayer
  -- your code here
Event:FireServer(playerWhoHeadToClone)
  -- your code etc

Second script:

event.OnServerEvent:Connect(function(playerWhoHeadToClone)
    PlayerEvent:FireAllClients(playerWhoHeadToClone)
end)

Third script:

event.OnClientEvent:Connect(function(playerWhoHeadToClone)
    -- your code here
end)

Here is the place file. It isn’t exactly like my game but it has a similar cloning feature.
CloneExample.rbxl (37.3 KB)

This is my progress so far:

CloneExample_Fixed.rbxl (37.8 KB)

Its not fixed yet, currently its inverted, you’ll see what I mean when you play it, I’ll fix that tomorrow as its late for me now, good night.

May I ask what you mean by it’s inverted?

Hey there I know it’s been a week but I tested the game out and I can see the problem. How can I fix the blocks to spawn only on the player that clicks and not everyone in the server?