My clone script is bugging

So im trying to clone a model from ServerStorage from a folder, when i try doing it, the code doesn’t seem to clone it, here’s the code.

				local selected
				local plrname = game.ReplicatedStorage.plrname
				local serverstorage = game:GetService("ServerStorage")
				local servermaps = serverstorage:FindFirstChild("__math.rad(1,4)")

				local minium,max = 1,2
				local num
					= math.random(minium,max)

				selected = servermaps[num]
				print(selected:GetAttribute("RealName").. " is the selected map.")
				plrname.Value = selected:GetAttribute("RealName")
				setplrname(plrname,selected:GetAttribute("RealName"))
				
				xpcall(function()
					return 	setplrname(plrname,selected:GetAttribute("RealName"))
				end, function(error3)
					warn("New error: "..tostring(error3))
					return;
				end)

				local new = selected:Clone()
				new.Parent = workspace
				for i,v in pairs(new:GetChildren()) do
					v.Parent = workspace
				end

				wait(0.5)
				new:Destroy()
				
				function enablescriptsEARLY(a,b)
					for i,v in pairs(a:GetDescendants()) do
						for class,class2 in pairs(b) do
							if v:IsA(class2) then
								v.Enabled = true
								v.Disabled = false
							end
						end
					end
				end

				if num == 2 then -- Here is the block where i get the issue
					enablescriptsEARLY(selected,defaultEnablingTable)
					local pulsar = serverstorage.NUM.PulsarMod:Clone() -- Right here
					pulsar.Parent = workspace
					enablescriptsEARLY(selected,defaultEnablingTable)
				end

				tweenservice:Create(G1,normalinfo,{
					CFrame = CFrame.new(workspace.G1_B_B.Position)
				}):Play()
				tweenservice:Create(G2,normalinfo,{
					CFrame = CFrame.new(workspace.G2_B_A.Position)
				}):Play()
				wait(2.2)
				G1.Transparency=1
				G2.Transparency=2

I did anything i could think to try and fix it but that just doesn’t do it.

If i got anything wrong, tell me please.

1 Like

Without any errors or logs to the output, it’s difficult to tell the issue.

local new = selected:Clone()
new.Parent = workspace
for i,v in pairs(new:GetChildren()) do
	v.Parent = workspace
end

wait(0.5) --should be task.wait(0.5)
new:Destroy()

This block of code should clone the object and put all of its children into the workspace, then destroy the original object after 0.5 seconds. The children should still be in the workspace.
Also,

local servermaps = serverstorage:FindFirstChild("__math.rad(1,4)")

should probably be

local servermaps = serverstorage:FindFirstChild("__math.rad(1,4)"):GetChildren()
2 Likes

Try this:

local selected
local plrname = game.ReplicatedStorage.plrname
local serverstorage = game:GetService("ServerStorage")
local servermaps = serverstorage:FindFirstChild("__math.rad(1,4)")
local tweenservice = game:GetService("TweenService")  -- Make sure you have this service

local minium, max = 1, 2
local num = math.random(minium, max)

selected = servermaps[num]
print(selected:GetAttribute("RealName") .. " is the selected map.")
plrname.Value = selected:GetAttribute("RealName")

local function setplrname(plrname, name) -- Assuming you have a setplrname function
    -- Implement the setplrname function logic here
end

xpcall(function()
    setplrname(plrname, selected:GetAttribute("RealName"))
end, function(error3)
    warn("New error: " .. tostring(error3))
end)

local new = selected:Clone()
new.Parent = workspace
for i, v in pairs(new:GetChildren()) do
    v.Parent = workspace
end

wait(0.5)
new:Destroy()

function enablescriptsEARLY(a, b)
    for i, v in pairs(a:GetDescendants()) do
        for class, class2 in pairs(b) do
            if v:IsA(class2) then
                v.Enabled = true
                v.Disabled = false
            end
        end
    end
end

local defaultEnablingTable = { -- You need to define this table
    -- Define classes that you want to enable
}

if num == 2 then
    enablescriptsEARLY(selected, defaultEnablingTable)
    local pulsar = serverstorage.NUM.PulsarMod:Clone()
    pulsar.Parent = workspace
    enablescriptsEARLY(selected, defaultEnablingTable)
end

local G1 = workspace.G1  -- Replace this with the actual object
local G2 = workspace.G2  -- Replace this with the actual object
local normalinfo = TweenInfo.new(1)  -- You need to define the tween info

tweenservice:Create(G1, normalinfo, {
    CFrame = CFrame.new(workspace.G1_B_B.Position)
}):Play()

tweenservice:Create(G2, normalinfo, {
    CFrame = CFrame.new(workspace.G2_B_A.Position)
}):Play()

wait(2.2)
G1.Transparency = 1
G2.Transparency = 0.5

EDIT: Read comments

2 Likes

The error is not the code, the problem is the model not being cloned into workspace and i don’t even have a script that destroys the part.

(The main code works fine, only the clone doesn’t work)

What does the output say, if anything?

Sorry to reply late, it doesn’t say any errors it just doesn’t clone it