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

Better way to make a MainModule? How would I go about it, or should I not bother changing it?

Asked by 4 years ago

My mainmodule:

if workspace:FindFirstChild("Sword Admin v3") then
    return {script; on = true;}
else
    print("Sword Admin is not inserted correctly into this place.")
    return {script; on = true;}
end

So, Is there? People constantly tell me there is but don't further explain it. All help is appreciated!

Note: It's 3am... I'm going to sleep so I'll check on this in the morning!

ALSO, YES, MY CODE DOES WORK!

1 answer

Log in to vote
1
Answered by 4 years ago

Yes there is.

assert(workspace:FindFirstChild("Sword Admin v3"),"Sword Admin is not inserted correctly into this place.")
return {script; on = true;}

assert is a function that takes 2 parameters. First one is a bool [a], second is string [b].

If a is false or nil, then assert errors b.

Keep in mind that FindFirstChild returns Instance or nil.

I don't understand why would you want to return script in a modulescript... If assert will error then the function will return nothing.

Additionally, you could try returning the table before calling assert.

Please mark as solved if helped. Thanks!

0
I return the script so that when it is required by the loader, it inserts the script. Thanks for helping! WideSteal321 773 — 4y
Ad

Answer this question