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

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

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.

3 comments

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.

0

There is no loop

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

1 answer

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?

2 comments

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

0

No errors, what is a lua debugger, and this is a server script and is located in the part

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