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:

 local S = game.Workspace
local T = game.ServerStorage
function cycle()
    local P = S:FindFirstChild()
    if P:IsA("Model") then
    repeat
    Parts()
    until
    P:FindFirstChild() == nil   
    end
end
function Parts()
    local C = P:FindFirstChild()
    if C:IsA("Part")then
    elseif C == nil then
    P.Parent = T.Analyzed
    repeat
    re()
    until
    T.Analyzing:FindFirstChild() == nil 
    else
    C.Parent = T.Analyzing
    end
end
function re()
    local R = T.Analyzing:FindFirstChild()
    if R ~= nil then
        R.Parent = P        
    end
end
function B()
    local M = T.Analyzed:FindFirstChild()
    if M ~= nil then
        M.Parent = S
    end
end
repeat
    cycle()
    wait(1)
until
S:FindFirstChild() == nil
repeat
B()
wait(1) 
until
T.Analyzed:FindFirstChild() == nil

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:

function Scan(Object)
    for i,v in pairs(Object:GetChildren())do    
        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.]]
        if v:IsA("Part") then
            --Change color, texture, etc here.
            Scan(v)
        else
            Scan(v)
        end     
    end
end

Scan(game.Workspace)
--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