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

Color3value.R printing as 1 even thought it should be 255?

Asked by 4 years ago

Hi all.

I'm making a lighting system of sorts, and I wanna send a preset colour (or one entered into a text box to to the server to tween all the lights to the corresponding colour, but sending the remotes is the hard part because I can't just send raw color3values through because they'll be split into 3 parts and I'm too lazy to fiddle with string.split stuff I decided to use Color3Value.R / Color3Value.G / etc for my remote system, this is the client side code;

    local R = preset1.Colour.Value.R
    local G = preset1.Colour.Value.G
    local B = preset1.Colour.Value.B
print(R)    
    print('hi')
    revent:FireServer(R,G,B)

Whenever I run this code, it prints 1 instead of the actual colo3value.R (255) The entire RGB value according to this system is 1,0,0 The server side is the only thing that functions correctly as it tweens all the lights to 1,0,0. How can I fix this, or is there an alternative to this?

1
Hello! If your problem is solved, i suggest marking the answer as accepted so both you and the answerer can get more reputation. Thanks! User#30567 0 — 4y

2 answers

Log in to vote
3
Answered by 4 years ago
Edited 4 years ago

If you look at the constructor of Color3.new() you see that it expects the R G B values ranged between [0-1]. if you did Color3.new(155,55,55) --example values then they will be set to 1 since it is the highest value. if you used Color3.fromRGB(155,155,55) then these values would be from a [0-255] range set to a [0-1] range so when you would access the properties of the above Color3 and you would get Red (aColor3.R) that would return 0.607 to get the original value back you have to math.ceil(0.607*255) which would return back 155

0
Thanks so much! VoidKeyword 111 — 4y
0
Np! Glad i could help VerdommeMan 1479 — 4y
Ad
Log in to vote
0
Answered by
sngnn 274 Moderation Voter
4 years ago

Color3 values have a range of 0-1. You could instead multiply R by 255, however that would return some odd values. You could fix those "odd values" by rounding it:

print(math.round((R*255)+.5))

Answer this question