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

Why wont a brick Change color when someone joins?

Asked by 7 years ago

Ok so I want this to change color when someone joins but it won't work, here is the script:

OnPlayerJoin function
    ColorSequence.new(Color3)
end

1
This isn't valid Lua code. It looks like you need some basic tutorials to get you started. You should check out the tutorials on the official ROBLOX wiki! http://wiki.roblox.com/index.php?title=Intro_to_Scripting duckwit 1404 — 7y

3 answers

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

Well, the problem is that you didn't set up your Function correctly. (Click on the highlighted word for how a Function is set up.) Other problems include that you used the ColorSequence function, when for this you have to use the BrickColor function; you also didn't give a valid color (you gave a function), and you didn't set anything up for the code to fire when the player joined: for this, you have to use the PlayerAdded event, which will fire when a player connects to the server.

An example of the PlayerAdded is the following; however, to note, the PlayerAdded event is only usable for the Players service: you can't use it for anything else, it's for the Players service only; now, onto the example:

function onPlayerJoin(plyr)
    -- 'plyr' is the argument for the player who connected: the PlayerAdded event returns the player, so you use an argument, such as the 'plyr' variable in this example, to accomplish this.
    print(plyr.Name, 'joined the server! :D')
    -- Will print in the Output. (More on this later.) Say for when I join the game, it'll print in the Output "TheeDeathCaster joined the server! :D"
end
-- Ends the function: for every function, it requires an end to end its job for the script - however, I'm not saying that you can't ever fire it again once it's used, not unless you don't use a function or a loop. (More on this later.)

game.Players.PlayerAdded:connect(onPlayerAdded)
-- As you can see, the PlayerAdded event is connected to the onPlayerAdded function, and that it's connecting that w/ the Players service. (Kinda hard to explain this; more on this later.) What this does is it waits for when a player connects to the server, and when the player connects, it'll fire the function that's given, and return the player. (As explained earlier)

Now, onto Colors, or BrickColors: for brick colors, to edit them via a script, you have to use the BrickColor, as stated earlier: doing something like just giving it a string w/o the function will not work, and will break your script. To note, however, do NOT confuse BrickColor w/ Color3, as they're entirely different functions who work for entirely different usages, being one works for bricks, while the other works for GUIs.

To note, however, you could combine the two functions together to make a powerful ally! But you need to be careful as to how you code them, as they'll break your script otherwise.

Alright, here's an example of how to use the BrickColor function:

local PartBrickColor = BrickColor.new('Really red')
-- The BrickColor function requires an argument, being the color of choice: to note, this is a MUST, you ALWAYS have to uppercase the first letter in the name, otherwise it wont read it as a valid colour, unless you give it a number. (More on this later.) (That's how 'color' is spelled in England, from what I heard.)
game.Workspace.BasePlate.BrickColor = PartBrickColor -- Will set the BasePlate's BrickColor to "Really red."

Now, onto what I heard earlier about combining the two functions! If you have a specific color you want for the brick, but it's the color of the GUI you want it to be, and it isn't on the palette, you can combine the BrickColor function & the Color3 function, and vise-versa!

Here's an example of this:

-- For this example, I wrote "GUI" instead of "...GUI.Property" b/c this is only an example of the usage of how to accomplish this.

local GUIBackgroundColor = GUI.BackgroundColor3 -- GUIBackgroundColor is defined for the GUI's colour.
-- Say the GUI is purple: when you give the BrickColor function the GUI colour, it'll return the color that the Color3 is!
game.Workspace.BasePlate.BrickColor = BrickColor.new(GUIBackgroundColor)
-- Will set the BasePlate's BrickColor to the colour of the GUIs; pretty neat, eh? The BrickColor function also accepts this as a valid argument! AWESOME!!

For the vise-versa of this, you can read about it here.

Aaaaand that's all there is to it. :P I didn't rewrite your code, b/c that's your job to do: we can't give you scripts; we can only help you w/ your scripting problems. (Although, under some circumstances, this is done anyways. XP)

Stuff touched on, but didn't go into great detail about

  1. Function - A most powerful tool in the scripting world: a function, if contained w/ code, can be fired multiple times, and prevents rewriting the same code over-and-over again; to call upon it, you just call upon its name.

  2. ColorSequence - Can't quite explain this, as I've never used this before. e-e Check out the WIKI docu for an explanation about this function.

  3. The Output - A powerful function, and a grand ally in the scripting world! It's essentially your best friend whenever you code. :P What it does is it returns feedback that was given to it, such as strings, numbers, errors, warnings, etc.

  4. I stated previously that "you ALWAYS have to uppercase the first letter in the name, otherwise it wont read it as a valid colour, unless you give it a number." (This is for when you give the BrickColor a string for the argument.) It's pretty self explanatory, but to recap, you require, for when you want to give a string for the colour to the BrickColor function, to uppercase the first letter in the name, otherwise it'll read it as a invalid argument, and return Nil. (If the WIKI docu was confusing, click here for a more explanatory explaination.)

  5. The PlayerAdded Event - As stated before, it will fire for when the player connects to the server, and will return it (if you're using a function, like to add leaderstats to the player); however, this event can NOT be used anywhere else other than the Players service: this event is for it only.

B/c it looks like you're starting out, I recommend you check out this WIKI docu for a tutorial on how to write code/ script. :) (Credit to duckwit for pointing this out! :D)

Hope this helped you in any way! :D

0
Nice answer! OldPalHappy 1477 — 7y
0
Thanx C; TheeDeathCaster 2368 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

This code isn't valid. You should watch some tutorials or check out the wiki to learn how to do this.

This should how it should look.

game.Players.PlayedAdded:Connect(function()
game.Workspace.Part.BrickColor = BrickColor.new("Really red") -- or whatever color you want
end
Log in to vote
-2
Answered by 7 years ago

Brick.BrickColor= whatever color it is

if parent then

Brick.BrickColor=what ever color you want it to be

Answer this question