Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I am a bit confused on function parameters, can I have some help please?

So is this correct?

function iamcool (thebrickcolor, isanchored, thetransperancy)
     local part = game.Workspace.Part
     part.Brickcolor = thebrickcolor
     part.Anchored = isanchored
     part.Transperancy = thetransperancy
end

iamcool (cyan, false, 0.5)

Please correct me if I am wrong.

3 comments

0

yes and no. You're passing a unformatted string on line 8, you have to use BrickColor.new("cyan") or "cyan"

0

Oh, ok I thought of that but I said “nvm” thanks!, what can I do to like yknow, accept your answer since it is a comment cuz I can not upvote?

0

????

1 answer

You are using parameters correctly, you can send them to functions and use them inside the function,, but there's a problem, everything is correct except for the color, first of all, it's part.BrickColor and not part.Brickcolor, remember: capilitization has to be correct, the second problem is that you are sending cyan which would essentially look like

part.BrickColor = cyan

Which will error, to fix it send the BrickColor to the function:

iamcool(BrickColor.new("Cyan"),false,.5)

There's one last problem, is that if you do

iamcool(BrickColor.new("Bright red")

It's gonna error because it's setting anchored and transparency to nil, so we should check if they exist first

function iamcool(brickcolor,shouldAnchor,transparency) -- you can name em anything
     if brickcolor then
        local part = workspace.Part
        part.BrickColor = brickcolor
       if shouldAnchor ~= nil then
           part.Anchored = shouldAnchor
           if transparency then
         part.Transparency = tonumber(transparency)
         end
       end
     end
end

So here we go We can now set just individual properties

iamcool(BrickColor.new("Really red"))

1 comment

0

Thanks man!

This discussion is preserved as it was. New answers, comments, and votes are closed.