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

What's wrong here?

Asked by 8 years ago

I wrote this script and something seems to be wrong. I have no idea what it is so can someone look it over and help me out. Thanks.

while wait(1) do
    math.randomseed(tick())
    local value = math.random(1,8)
        Color = script.Parent.BrickColor
        if value == 1 then 
            Color = BrickColor.new("Really Red")
        elseif value == 2 then 
            Color = BrickColor.new("Lime green")
        elseif value == 3 then
            Color = BrickColor.new("Hot pink")
        elseif value == 4 then
            Color = BrickColor.new("New Yeller")
        elseif value == 5 then
            Color = BrickColor.new("Toothpaste")
        elseif value == 6 then
            Color = BrickColor.new("Burnt Sienna")
        elseif value == 7 then
            Color = BrickColor.new("Really black")
        elseif value == 8 then
            Color = BrickColor.new("Peral")
    end
end
0
Setting a variable to a value doesn't attach it to where that value came from. 1waffle1 2908 — 8y

2 answers

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

Problem

Your script is reading line 4 as a line it needs to remember, not as a property that needs to be changed. Just removing the .BrickColor from that line will make the script remember the value as a object, which if you reference it later in the script with .BrickColor afterward. The script will realise that you're intending to change the value of the object.


Solution

while wait(1) do
    math.randomseed(tick())
    local value = math.random(1,8)
        Color = script.Parent --Just remove the .BrickColor and the script will recognize the 'Color' variable as a object.
        if value == 1 then 
            Color.BrickColor = BrickColor.new("Really Red") --Adding the .BrickColor to the end of the variable will make the script realise it is a property needing to change.
        elseif value == 2 then 
            Color.BrickColor = BrickColor.new("Lime green")
        elseif value == 3 then
            Color.BrickColor = BrickColor.new("Hot pink")
        elseif value == 4 then
            Color.BrickColor = BrickColor.new("New Yeller")
        elseif value == 5 then
            Color.BrickColor = BrickColor.new("Toothpaste")
        elseif value == 6 then
            Color.BrickColor = BrickColor.new("Burnt Sienna")
        elseif value == 7 then
            Color.BrickColor = BrickColor.new("Really black")
        elseif value == 8 then
            Color.BrickColor = BrickColor.new("Peral")
    end
end

How your script was reading it before probably was like this. Repeat randomseed: get a value: remember the part's BrickColor for later being Mid gray: if statement: value is equal to two: alright remember the BrickColor Lime Green: wait a second: alright randomseed: get value: remember Lime Green since that's the color of the Brick: value is 5: remember Toothpaste. And it just goes on just remember the changing variable instead of actually changing the property of the object.

0
Still doesn't work. TetsuyaMitsuru 10 — 8y
0
Can you open output and tell us if there are any errors? M39a9am3R 3210 — 8y
Ad
Log in to vote
-2
Answered by
lucas4114 607 Moderation Voter
8 years ago

I don't know if it changed but I think with BrickColor.new you don't put the name but the id of a color, here's a list of all of them: http://wiki.roblox.com/index.php?title=BrickColor_Codes

Answer this question