Cloning a part breaks the script within the part

I would like to clone a part in a LocalScript while maintaining the functionality of the script within said part. The issue is that once cloned, the part’s script ceases to work.

My understanding is that this does not work because you can’t clone a server script in a LocalScript. So, I thought I’d use a Remote Function and do the cloning in a server script.

This is what the server script used to clone looks like:

local function onCloneBall(player,character,ball)
	local clientBall = ball:Clone()
	clientBall.Parent = game.Workspace
	clientBall.CanCollide = true
	return clientBall
end

cloneBall.OnServerInvoke = onCloneBall

It takes in a ball that I want to be cloned.

In the LocalScript:

local clientBall = cloneBall:InvokeServer(character,projectile)

I retrieve the cloned ball, called ‘clientBall’.

Yet the problem still persists – the script within the cloned ball does not work.

I don’t understand why this is the case? I use a RemoteFunction to do the cloning from the server script, so I don’t really understand why it isn’t working. Any help would be appreciated!

2 Likes

Localscripts will only run when parented under:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service

(taken from the devwiki pages on this, LocalScript | Roblox Creator Documentation)

The LocalScript is running. The server script parented under the part in Workspace is not running once cloned.

Is the part that’s being cloned inside the ReplicatedStorage?

wait, are you cloning the server-script… on the localscript?

Nah it’s in the workspace. I’ve tried to put it in both replicatedstorage and serverstorage as well

I’m cloning the part with the server script inside from the local script, ya. But I used a remote function which I thought would make it work because the cloning would be done serverside, but maybe I misunderstand how that works