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

How cay I delete certain children?

Asked by 6 years ago
Edited 6 years ago

I want to make a game where soldiers can fight each other, but I have trouble deleting the soldiers after the fight. Can someone help me with that? This is the code I have now:

    local fromsoldiers = {}
    local tosoldiers = {}
    for i,v in pairs(attackedfrom:GetChildren())do

        if v.ClassName == "Model" then
            fromsoldiers[#fromsoldiers+1] = v
        end
    end
    for i,v in pairs(attackedto:GetChildren())do
        if v.ClassName == "Model" then
            tosoldiers[#tosoldiers+1] = v
        end
    end


    --compare
    if #tosoldiers-#fromsoldiers>=1 then
        print("defence won")
        for i=1,#fromsoldiers do
            print(tosoldiers[#tosoldiers-i]) --everything is fine
            for i,v in pairs(attackedto:GetChildren())do
                if v.ClassName == "Model" then
                    if v.Name == tosoldiers[#tosoldiers-i] then
                        v:Destroy() --doesnt work
                    end
                end
            end
        end
    end

edit: I changed part of my code

if p.Name == tosoldiers[#tosoldiers-i].Name then
    print(s,p.Name.." is the same as "..tosoldiers[#tosoldiers-i].Name)
else
    print(s,p.Name.." and "..tosoldiers[#tosoldiers-i].Name.." are not the same")
end

but now it gives a really weird output:

defence won Player2's soldier0 and Player2's soldier1 are not the same Player2's soldier1 is the same as Player2's soldier1 Player2's soldier2 and Player2's soldier1 are not the same Player2's soldier0 is the same as Player2's soldier0 Player2's soldier1 and Player2's soldier0 are not the same Player2's soldier2 and Player2's soldier0 are not the same

0
hey can you please explain where the soldiers are placed inside the workspace and what are their names then i'll be able to help you! Elixcore 1337 — 6y
0
also all you want is to delete them after the fight (after they all died), is that right? Elixcore 1337 — 6y
0
there is a model in the workspace, in the model are unions, in the unions are the soldiers and some values. Their names are: player.Name+'s soldier+the amount of soldiers on that part. And yes, I only want to delete them, but not all of them, only the amound of fromsoldiers. saveourwolves 2 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

edit: i understand it now make it get all the children in the folder and set there parent to a folder after the battle then delete the folder and recreate it afterwards

Ad

Answer this question