Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Failing to clone an object?

Asked by 9 years ago

In my game, I have building platforms. When the player dies, their building platform resets. When the player first joins the game, I clone their building platform into Replicated Storage. So when the player dies, I can easily clone that platform and put it in their folder. (I also put a Object value inside each building platform to have a way to check if it's that players building platform or not.)

Apparently, my BaseAssigner script in Server Script service is not cloning the player's Building Platform.

Line 91 Building Platform is not a valid member of Folder

if b.BuildingPlatform.Owner.Value == playa.Name and v.BuildingPlatform == nil then -- Makes sure the building platform is theirs | Also checks to see if they already have a building platform (Look below for the code -- This line above is in the second script that checks if the player dies)

Here are a few snapshots of my hierarchy and game.

http://prntscr.com/7vcp7q -- hierarchy

http://prntscr.com/7vcpsu -- Game

Hopefully I've explained thoroughly enough. If not, please ask.

Here is my script that handles the bases and clones the BuildingPlatform into Replicated Storage for later use.

AvailableBases = {'Base6','Base5','Base4','Base3','Base2','Base1'}
game.Players.PlayerAdded:connect(function(plr)
  local var = #AvailableBases
  local team = AvailableBases[var]
  table.remove(AvailableBases,var)
  workspace.Bases:FindFirstChild(team).BaseOwner.Value = plr.Name
    for _,v in pairs(workspace.Bases:FindFirstChild(team).PlayerParts:GetChildren()) do
        v.PartOwner.Value = plr.Name
        v.BuildingPlatform.Owner.Value = plr.Name -- Sets their Building Platform Ownership value to their name
        local NewPlatform = v.BuildingPlatform:Clone() -- Clones the Building Platform and is now referenced as NewPlatform
        NewPlatform.Parent = game.ReplicatedStorage -- Stores a copy in Replicated Storage
    end

Here is what I do when the player dies.

hum.Died:connect(function() -- WHEN THE PLAYER DIES
    for _,v in pairs(game.Workspace.Bases:GetChildren()) do
        if v.BaseOwner.Value == playa.Name then
            v.Shield.One.Transparency = 0
            v.Shield.Two.Transparency = 0.4
            v.Shield.One.CanCollide = true
            v.Shield.Two.CanCollide = true
            wait(2)
            v.ClonedParts:ClearAllChildren() -- Deletes all parts they edited.


            for _,b in pairs(game.ReplicatedStorage:GetChildren()) do -- Gets Children of Replicated Storage
                if b.BuildingPlatform.Owner.Value == playa.Name and v.BuildingPlatform == nil then -- Makes sure the building platform is theirs | Also checks to see if they already have a building platform
                    b.BuildingPlatform.Parent = v -- Puts BuildingPlatform in their base


            for _,v in pairs(playa.PlayerGui:GetChildren()) do
                        if v:IsA("SelectionBox") or v:IsA("Handles") or v:IsA("SelectionPartLasso") then 
                    v:Destroy()
                        end
                    end
                end
            end
        end
    end
end)

Answer this question