Hello, I am trying to clone a model that is stored locally in a ViewportFrame via a RemoteEvent. However, the output is showing attempt to index nil with 'Parent'
If you could help debug, that would be great.
Local Script:
if Credits.Value >= DroidModule.Repaint.BuyPrice then
if PrimaryButton.BackgroundTransparency == 0 and SecondaryButton.BackgroundTransparency == 0 and TertiaryButton.BackgroundTransparency == 0 and Owned.Value == true then
SuccessFunction("REPAINTING...")
local DroidPreview = EquipFrame.Preview.ViewportFrame:FindFirstChildWhichIsA("Model")
RepaintEvent:FireServer(DroidPreview:Clone())
task.spawn(function()
SuccessFunction("SUCCESSFULLY REPAINTED")
PaintSound:Play()
end)
elseif Owned.Value == false then
ErrorFunction("NO DROID FOUND")
elseif PrimaryButton.BackgroundTransparency ~= 0 or SecondaryButton.BackgroundTransparency ~= 0 or TertiaryButton.BackgroundTransparency ~= 0 then
ErrorFunction("SELECT PRIMARY, SECONDARY & TERTIARY COLOURS")
end
After cloning the model parent it to replicated storage and then fire it through the remote event because when you clone a model it doesn’t have a parent.
if Credits.Value >= DroidModule.Repaint.BuyPrice then
if PrimaryButton.BackgroundTransparency == 0 and SecondaryButton.BackgroundTransparency == 0 and TertiaryButton.BackgroundTransparency == 0 and Owned.Value == true then
SuccessFunction("REPAINTING...")
local DroidPreview = EquipFrame.Preview.ViewportFrame:FindFirstChildWhichIsA("Model"):Clone()
DroidPreview.Parent = ReplicatedStorage
RepaintEvent:FireServer(DroidPreview)
task.spawn(function()
SuccessFunction("SUCCESSFULLY REPAINTED")
PaintSound:Play()
end)
elseif Owned.Value == false then
ErrorFunction("NO DROID FOUND")
elseif PrimaryButton.BackgroundTransparency ~= 0 or SecondaryButton.BackgroundTransparency ~= 0 or TertiaryButton.BackgroundTransparency ~= 0 then
ErrorFunction("SELECT PRIMARY, SECONDARY & TERTIARY COLOURS")
end
The reason it’s nil is because you’re cloning the preview on the client, but then asking the server to do something with it. Since the model was cloned on the client, the server can’t access it. A better way might be to name each model uniquely and store them on the server or in ReplicatedStorage (which both the server and client can access). Then, you can send the model’s name from the client to the server using a RemoteEvent. The server can then find the model you want, clone and then parent the model into the character on the server, meaning all players will see it as you described you wanted.