Model dosn't clone correctly

In a server script, i want to clone a model with a model inside it and parent it to workspace. Whenever I press v, it fires a remote event to the server which does the cloning.

local ServerStorage = game:GetService("ServerStorage")
local te = {}

Event4.OnServerEvent:Connect(function(player, key, pos)
	local playerUserId = player.UserId
	te[playerUserId] = ServerStorage.Zushi:WaitForChild("Rocks"):Clone()
	te[playerUserId].Parent = game.Workspace
	te[playerUserId]:SetPrimaryPartCFrame(CFrame.new(pos.X, pos.Y+75, pos.Z))
end)

image
Rocks2 has a lot of children parts inside.

The problem arises after i clone the first one. The first time i clone it, it clones perfectly fine with all the children. But The 2nd time i clone it, all the children in rocks2 dont get cloned with it, and throws an error for what happens next, when i try to setprimarypartcframe on Rocks2. Since the children of rocks2 didnt get cloned, the primarypart wont be found.

I suggest you put a table inside the dictionary.

local ServerStorage = game:GetService("ServerStorage")

local te = {}

Event4.OnServerEvent:Connect(function(player, key, pos)

local playerUserId = player.UserId
if not te[playerUserId] then
    te[playerUserId] = {}
end

table.insert(te[playerUserId], ServerStorage.Zushi:WaitForChild("Rocks"):Clone())

te[playerUserId][#te[playerUserId]].Parent = workspace

te[playerUserId][#te[playerUserId]].Parent:SetPrimaryPartCFrame(CFrame.new(pos.X, pos.Y+75, pos.Z))

end)

That wont work with he full code. There is a num sequence which fires with the event, and if i do this, i would clear the table and nto be able to access it during the 2nd time i fire

1 Like

I edited the code, I forgot to add a condition.

Can I get the model you are trying to clone?

RocksModel.rbxm (267.4 KB)

This might have to do with the old model getting overwrited. What is the pos variable represent? This also might be the problem.

the mouse.hit.p. it dosnt cause any problems

Just try this script alone

local ServerStorage = game:GetService("ServerStorage")

Event4.OnServerEvent:Connect(function(player, key, pos)
	local model = ServerStorage.Zushi:WaitForChild("Rocks"):Clone()
    print(model)
	model:SetPrimaryPartCFrame(CFrame.new(pos.X, pos.Y+75, pos.Z))
    model.Parent = game.Workspace
end)

If this doesn’t work its probably something outside of the script you sent. It also could be the local script sending the wrong parameters.

The rock model inside server storage never changes right?

It’s weird
It works for me

Is there any error in the output?

It gives the error, no primary part is found and rocksmid is not found

Well, first remove all scripts inside the rocks
And put one script inside the Rocks2 model
The script:

for i, rock in pairs(script.Parent:GetChildren()) do
	if rock:IsA("BasePart") then
		rock.Touched:Connect(function() end)
		local t = rock:GetTouchingParts()
		if t[1] then
			rock.Material = t[1].Material
			rock.Color = t[1].Color
		end
	end
end

This would be much better if you didn’t use a special script for each rock

I apparently had to set te[playeruserId] to nil during after the first sequence was fired or it would change the first one, which i would later delete which would cause the error.

Now take a screenshot of the output