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)
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.
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
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.