I am currently making IFE (In Flight Entertainment) and I decided to have a Misc. option where you can change the colour of the fog. The way I am doing this is by having a loop go off every second checking the colour. The problem is that the only colour it changes to is red. If I put 255 in the text box, it will give me red. If I put 255,255,255 in the text box I get black for some reason. It is in RGB. My local script:
1 | while true do |
2 | wait( 1 ) |
3 | game.Lighting.FogColor = Color 3. new(script.Parent.Text) |
4 | end |
It previously was:
1 | while true do |
2 | wait( 1 ) |
3 | game.Lighting.FogColor = Color 3. fromRGB(script.Parent.Text) |
4 | end |
Any help is appreciated!
My idea is to probably make three textboxes for red, green and blue. And then combine all the text with tonumber()
Here's a quick example on how you can combine several values:
1 | print ( "test" .. 1 + 2 .. "!" ) |
2 | --output: test3! |
If you want to use this script I made, make sure your textboxes exist where the script is looking for them.
1 | while wait() do |
2 | if tonumber (script.Parent.Red.Text) and tonumber (script.Parent.Green.Text) and tonumber (script.Parent.Blue.Text) then |
3 | game.Lighting.FogColor = Color 3. fromRGB( tonumber (script.Parent.Red.Text) .. ", " .. tonumber (script.Parent.Green.Text) .. ", " .. tonumber (script.Parent.Blue.Text)) |
4 | end |
5 | end |
string.split
would be very useful for this. You could take each individual number and apply it to the rgb color.
For example:
1 | while true do |
2 | wait() |
3 | local rgbValues = string.split(script.Parent.Text, “,”) |
4 | If tonumber (rgbValues [ 1 ] and tonumber (rgbValues [ 2 ] and tonumber (rgbValues [ 3 ] and #rgbValues = = 3 then |
5 | game.Lighting.FogColor = Color 3. fromRGB( tonumber (rgbValues [ 1 ] , tonumber (rbgValues [ 2 ] , tonumber (rgbValues [ 3 ] ) |
6 | end |
7 | end |
Sorry if my spacing was a bit weird, it’s because I typed all of this on mobile. Hopefully you get the gist of it. I basically check if there are 3 numbers in the textbox by separating them from the commas in the text. Technically u should be checking if they are positive integers as well because I don’t think rgb takes negative numbers.