Prixo
Prixo

Reputation: 13

Roblox Studio Lua : Clone with local script

I created a template or when someone touches that template, it's destroyed, but it's only for that person. I try to clone the model with a local script, but it does not work.

local part2 = script.Parent.MarioBrick:Clone()
part2.Parent = game.Workspace.Camera

Upvotes: 1

Views: 2752

Answers (2)

Hullburg
Hullburg

Reputation: 111

I believe cloning the script's parent will also clone the script itself, and run the script again. Are you doing this intentionally? If not then it can cause strange side effects to happen.

Edit: Sorry, I misread your code.

Upvotes: 0

Kylaaa
Kylaaa

Reputation: 7188

Your code looks fine. I suspect that your problem is that your LocalScript is not in a place that is run by clients. If you want a LocalScript to run, it needs to exist on a Player's model somewhere. An easy way to do this is to add the LocalScript into StarterPlayer > StarterCharacterScripts This will clone the contents into the character when they spawn. Here's my example that seems to work :

local testPart = Instance.new("Part")
testPart.BrickColor = BrickColor.Random()
testPart.Position = Vector3.new(math.random(-10, 10), 1, math.random(-10, 10))
testPart.Parent = game.Workspace.Camera

When I go into the Test tab, I can start a server with 3 players. Each of those 3 players will see a different color cube somewhere different.

Upvotes: 0

Related Questions