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

Changing Fog Colour Through TextBox?

Asked by 4 years ago

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:

while true do
    wait(1)
    game.Lighting.FogColor = Color3.new(script.Parent.Text)
end

It previously was:

while true do
    wait(1)
    game.Lighting.FogColor = Color3.fromRGB(script.Parent.Text)
end

Any help is appreciated!

0
someone help xd electrocat56 18 — 4y
0
I made my own version and it doesn't work either... Nguyenlegiahung 1091 — 4y
0
rip electrocat56 18 — 4y

2 answers

Log in to vote
0
Answered by
EmK530 143
4 years ago
Edited 4 years ago

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:

print("test" .. 1 + 2 .. "!")
--output: test3!

If you want to use this script I made, make sure your textboxes exist where the script is looking for them.

while wait() do
    if tonumber(script.Parent.Red.Text) and tonumber(script.Parent.Green.Text) and tonumber(script.Parent.Blue.Text) then
        game.Lighting.FogColor = Color3.fromRGB(tonumber(script.Parent.Red.Text) .. ", " .. tonumber(script.Parent.Green.Text) .. ", " .. tonumber(script.Parent.Blue.Text))
    end
end
0
alot more complex than i expected electrocat56 18 — 4y
0
well uhh lemme know if it works EmK530 143 — 4y
0
anyway upvoted EmK530 143 — 4y
0
(larm_uh is my alt's name) error: Players.larm_uh.PlayerGui.Misc.Background.FogColour.ColourSetter:2: attempt to concatenate string with nil electrocat56 18 — 4y
View all comments (6 more)
0
also will that repeatedly change colour? or just for the start? electrocat56 18 — 4y
0
repeatedly EmK530 143 — 4y
0
o electrocat56 18 — 4y
0
didnt work electrocat56 18 — 4y
2
this method would’ve worked if you didn’t try to concatenate the rgb values. Replace every ..”, “.. with , Brandon1881 721 — 4y
0
thankyou brandon. now it works and i can continue developing other parts of it electrocat56 18 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

string.split would be very useful for this. You could take each individual number and apply it to the rgb color.

For example:

while true do
     wait()
     local rgbValues = string.split(script.Parent.Text, “,”)
     If tonumber(rgbValues[1] and tonumber(rgbValues[2] and tonumber(rgbValues[3] and #rgbValues == 3 then
     game.Lighting.FogColor = Color3.fromRGB(tonumber(rgbValues[1], tonumber(rbgValues[2], tonumber(rgbValues[3])
     end
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.

0
Upvoted. This is the perfect answer given the problem, from a user perspective having 3 textboxes like the other answer said would probably be better though blowup999 659 — 4y

Answer this question