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

BrickColor isn't a valid member of Part?

Asked by
Orian2 5
9 years ago

Hey, so I'm a newbie Lua scripter, and I'm trying to get a platform to move when I click a button. I managed to make it move 100 studs and return very easily, but if someone clicked the button while the platform was still moving it'd screw everything up, the velocity the platform had for people not to fall off, would grow by 15 on each click, and the studs the platform moved would also grow by 100 on each click. So i tried to create a way to make the button become inactive while the platform was moving, so I tried to make the function "move" work depending on the brick color, if the button was green or "Camo" in this case, the rest of the code would continue, changing the button's color to Red, or "Bright Red" in this case, so the button wouldn't activate the script again if clicked, and at the end of the function when the platform was back to it's original position and velocity, I'd once again change the button's color to "Camo" so it could be used again. I was very happy with this idea, but like 99.9% of the stuff I usually script don't work that well, the Studio types on the command box: "10:02:33.491 - Brickcolor is not a valid member of Part" I am no idea why it doesn't work, the only guess I can make is it's because I pobably messed up while using the if term, anyways, here's the script:


p=game.Workspace.Bridge.Part Button=game.Workspace.Bridge.Button function move () if Button.Brickcolor == ("Camo") then Button.Brickcolor = Button.Brickcolor.new("Bright Red") p.Velocity = p.Velocity + Vector3.new(-15,0,0) for i=1,200 do p.CFrame = p.CFrame + Vector3.new(-.5,0,0) wait() end p.Velocity = p.Velocity + Vector3.new (15,0,0) wait(3) p.Velocity = p.Velocity + Vector3.new(15,0,0) for i=1,200 do p.CFrame = p.CFrame + Vector3.new(.5,0,0) wait() end p.velocity = p.velocity + Vector3.new(-15,0,0) wait(2) Button.Brickcolor = Button.Brickcolor.new("Camo") end end Button.ClickDetector.MouseClick:connect(move)

I'm pretty sure this is one of the worst approaches possible to creating a moving platform, o if anyone would be kind enough to show me their way of creating a simple moving platform with better ways, for example "while true do..." or something, I'd be grateful, as I said I'm still newbie so I gotta script the way I can.

0
Can you put it in Lua format 1st? davness 376 — 9y
0
My bad, just did it, sorry. Orian2 5 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

In ROBLOX Lua, everything is case sensitive. That means if one thing is not capitalized correctly, the whole script will break. To fix this, you need to make Brickcolor on lines 4, 5 and 20 BrickColor.

p=game.Workspace.Bridge.Part
Button=game.Workspace.Bridge.Button
 function move () 
    if Button.BrickColor == ("Camo") then
    Button.BrickColor = Button.Brickcolor.new("Bright Red") 
    p.Velocity = p.Velocity + Vector3.new(-15,0,0)
    for i=1,200 do
    p.CFrame = p.CFrame + Vector3.new(-.5,0,0)
    wait()
    end
    p.Velocity = p.Velocity + Vector3.new (15,0,0)
    wait(3)
    p.Velocity = p.Velocity + Vector3.new(15,0,0)
    for i=1,200 do
    p.CFrame = p.CFrame + Vector3.new(.5,0,0)
    wait()
    end
    p.velocity = p.velocity + Vector3.new(-15,0,0)
    wait(2)
    Button.BrickColor = Button.Brickcolor.new("Camo")
    end 
end
Button.ClickDetector.MouseClick:connect(move)

Other problems:

First of all, if you want to compare a BrickColor by it's name, you should use the Name property of the BrickColor, like this:

if Button.BrickColor.Name == "Camo" then

Next, you only need BrickColor.new() when creating a BrickColor, so you don't need your part name in there.

Overall, your script should finally be like this:

p=game.Workspace.Bridge.Part
Button=game.Workspace.Bridge.Button
 function move () 
    if Button.BrickColor.Name == "Camo" then
    Button.BrickColor = BrickColor.new("Bright Red") 
    p.Velocity = p.Velocity + Vector3.new(-15,0,0)
    for i=1,200 do
    p.CFrame = p.CFrame + Vector3.new(-.5,0,0)
    wait()
    end
    p.Velocity = p.Velocity + Vector3.new (15,0,0)
    wait(3)
    p.Velocity = p.Velocity + Vector3.new(15,0,0)
    for i=1,200 do
    p.CFrame = p.CFrame + Vector3.new(.5,0,0)
    wait()
    end
    p.velocity = p.velocity + Vector3.new(-15,0,0)
    wait(2)
    Button.BrickColor = BrickColor.new("Camo")
    end 
end
Button.ClickDetector.MouseClick:connect(move)

I hope this helped. If it did, be sure to accept my answer.

Learn more about BrickColors here.

0
Thank you very much! You helped me quite a lot! Orian2 5 — 9y
0
You're welcome. Spongocardo 1991 — 9y
Ad

Answer this question