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

Why does this not work when I am trying to change color of a brick?

Asked by 4 years ago
Part = script.Parent
Part1 = game.Workspace.ColorChangingPart
ILikeFood = true

if ILikeFood == true then
    Part.BrickColor = BrickColor.Random()
end

if ILikeFood == true then
script.Parent.ClickDetector.MouseClick:Connect(function(fdgdgd)
    Part1.BrickColor = BrickColor.Random()
    end)
    end

What I am trying to achieve: I want the 'Part' to change to a random color as soon as the game starts forever. I also want 'Part1' to change to a random color forever when 'Part' is clicked once.

Errors: None

What happens: 'Part' does not change color at all and 'Part1' only changes color once.

0
Also you'll learn this as you get better at scripting but, don't name your variables things like 'ILikeFood'. It makes your script harder for others to read, look sloppy, unorganized, and harder on yourself. You should be giving variables proper names. Rinextel 291 — 4y
0
There is no loop NoelGamer06 62 — 4y
0
just tried your script and it works!. Not sure whats going on but the part where your script is in changed color once on loading then as you click that said part the second part changed color randomly. might be roblox having a seizure again lol TGazza 1336 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Maybe you could try this out:

Part = script.Parent
Part1 = workspace.ColorChangingPart
ILikeFood = true

script.Parent.ClickDetector.MouseClick:Connect(function()
    if ILikeFood == true then
        Part1.Color = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))
    end
end)

Tell me if Part1 changes colors. If it doesn't, I have a few questions:

Does it have any errors in the output?

Have you ever tried using the Lua Debugger to find what the issue is out?

Is this a server script, and is it actually located in Part?

0
I'm pretty sure you can't use math.random with BrickColor. When using BrickColor, you have to use a string, using math.random generates a random number between 0 and 1, and the script doesn't know what to do with that info, that's why there's no output. You need to use Color3.fromRGB and you need to add perimeters to math.random so it's not just 0-1 ScaredWalkerr 0 — 4y
0
No errors, what is a lua debugger, and this is a server script and is located in the part DevSeveral 19 — 4y
Ad

Answer this question