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

What's wrong here?

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

1 comment

0

Setting a variable to a value doesn't attach it to where that value came from.

2 answers

✓ Accepted answer

##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.

2 comments

0

Still doesn't work.

0

Can you open output and tell us if there are any errors?

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