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

Error: attempt to call method 'Destroy' (a nil value)?

Asked by 6 years ago
game.Players.PlayerAdded:connect (function(players)
     players.CharacterAdded:connect (function(character)
        --Waiting
        game.ServerStorage:WaitForChild("UniformCode")
        local plrfile = game.ServerStorage.UniformCode:WaitForChild(players.Name)
        local Codes = plrfile:WaitForChild("Codes")


        local Hats1 = Codes:WaitForChild("Hats1")
        local Hats2 = Codes:WaitForChild("Hats2")
        local Hats3 = Codes:WaitForChild("Hats3")
        local Shirts = Codes:WaitForChild("Shirts")
        local Pants = Codes:WaitForChild("Pants")
        local BodyColors = Codes:WaitForChild("BodyColors")
        local Express = Codes:WaitForChild("Expressions")

        --Assigning
        if BodyColors.Value == 0 then
            character:GetChildren("Body Colors"):Destroy()
        end
    end)
end)

Alright I have this script when you join the game it gives random outfit, well I'm working on a script that does so. Anyway my problem happens on line 19 when Im trying to remove all the things the player has(exp their bodycolor) can someone tell me how to remove BodyColors from the players model?

0
GetChildren() does not get arguments passed to it, and will return a table of items. Instead try, character:FindFirstChild("Body Colors") Trewier 146 — 6y
0
it should be character[Body Colors]:GetChildren():Destroy or character:FindFirstChild ("Body Colors"):Destroy () abnotaddable 920 — 6y
1
You can't destroy a table..................... hiimgoodpack 2009 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago

When you getchildren, you're returning a read-only table of values.

:destroy() is also not a method of a table.

You should use a for loop and index each player and destroy the bodycolors from there.

if you assign the children of character to a variable, you can do this.

local BodyColors = character:GetChildren()

for i=1, #BodyColors do
    if BodyColors[i]:IsA("Body Color") then
        BodyColors[i]:Destroy()
    end
end
Ad
Log in to vote
0
Answered by
Viking359 161
6 years ago

basically anything with a lowercase letter directly after a : like :destroy is deprecated. :Destroy() itself though is deprecated too, so :Remove() would work. For your purposes, though, you can't just remove the body colors. You have to set them to something like fossil grey or something like that.

0
No. Workspace is deprecated (the global, not service), and now you have to use workspace. Wait() is deprecated, you need to use wait(). hiimgoodpack 2009 — 6y
0
Also, :Remove was deprecated in favor of :destroy. Then, :destroy got deprecated for :Destroy. hiimgoodpack 2009 — 6y

Answer this question