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

Why won't my analyzing script work?

Asked by 9 years ago

I am trying to make a script that will cycle through models and turn them into a certain material depending on what color it is. Right now I only have the script that will cycle through it, but it won't work. The error it gives me is " Argument 1 missing or nil." It is in a server script. This is the code:

01local S = game.Workspace
02local T = game.ServerStorage
03function cycle()
04    local P = S:FindFirstChild()
05    if P:IsA("Model") then
06    repeat
07    Parts()
08    until
09    P:FindFirstChild() == nil  
10    end
11end
12function Parts()
13    local C = P:FindFirstChild()
14    if C:IsA("Part")then
15    elseif C == nil then
View all 46 lines...

Edit: I know it won't change the material yet since I have not coded it in yet. I am just trying to see if it will move the materials to the holding folder.

1 answer

Log in to vote
1
Answered by 9 years ago

The reason this script errored is because you forgot to place the arguments in for all of the "FindFirstChild()" functions. Placing those arguments in should fix the script.

Example Code:

01function Scan(Object)
02    for i,v in pairs(Object:GetChildren())do   
03        wait() --[[Place a wait here or else your game/studio will lag or crash depending on the amount of objects that were in you first scan.]]
04        if v:IsA("Part") then
05            --Change color, texture, etc here.
06            Scan(v)
07        else
08            Scan(v)
09        end    
10    end
11end
12 
13Scan(game.Workspace)
14--This script will scan though the object that you place in arg1 of the function "Scan".

Is this what you are looking for?

0
Is there a way to use find first child for any name? ADeadlyGuest4 62 — 9y
0
Not that I know of, In this situation I think I'd use "for i,v in pairs(object:GetChildren()) do". ClassicTheBlue 65 — 9y
0
Here, I'll write another answer contaning the script that I'd write. ClassicTheBlue 65 — 9y
0
Thanks, that is a lot simpler and faster than my script. ADeadlyGuest4 62 — 9y
Ad

Answer this question