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

Color3 Value Not Converting Correctly?

Asked by
Donut792 216 Moderation Voter
4 years ago

alright so what i mean by this is that i have a local script that grabs a Color3 value that is inside the scripts parent and it sends that over to the server but when the server prints it off it comes out as decimals but changes the BodyColor3s to the correct color which doesnt make any sense in my mind but... the reason i made it use the individual rgb values is because just using a color3 value it would set it as the wrong color on both sides and the color would be different on both sides (say i send over tan you would be royal blue on the server and institutional white on the client which also makes no sense whatsoever)

LocalScript:

local NextButton = script.Parent.Next
local PreviousButton = script.Parent.Previous
local WhiteHex = script.Parent.White.Value
local TanHex = script.Parent.Tan.Value
local LatinoHex = script.Parent.Latino.Value
local LightskinHex = script.Parent.Lightskin.Value
local BrownHex = script.Parent.Brown.Value
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local LocalColor = Instance.new("Color3Value")
LocalColor.Name = "LocalColor"
LocalColor.Parent = Player
local Event = game.ReplicatedStorage.CharacterTraits.ColorChosen
local Value = 1

NextButton.MouseButton1Click:Connect(function()
    if Value == 1 then
        Value = Value + 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = WhiteHex
                v.LeftArmColor3 = WhiteHex
                v.LeftLegColor3 = WhiteHex
                v.RightArmColor3 = WhiteHex
                v.RightLegColor3 = WhiteHex
                v.TorsoColor3 = WhiteHex
                LocalColor.Value =(WhiteHex)
                Event:FireServer(WhiteHex.R,WhiteHex.G,WhiteHex.B)
            end
        end
    elseif Value == 2 then
        Value = Value + 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = TanHex
                v.LeftArmColor3 = TanHex
                v.LeftLegColor3 = TanHex
                v.RightArmColor3 = TanHex
                v.RightLegColor3 = TanHex
                v.TorsoColor3 = TanHex
                LocalColor.Value =(TanHex)
                Event:FireServer(TanHex.R,TanHex.G,TanHex.B)
            end
        end

    elseif Value == 3 then
        Value = Value + 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = LatinoHex
                v.LeftArmColor3 = LatinoHex
                v.LeftLegColor3 = LatinoHex
                v.RightArmColor3 = LatinoHex
                v.RightLegColor3 = LatinoHex
                v.TorsoColor3 = LatinoHex
                LocalColor.Value =(LatinoHex)
                Event:FireServer(LatinoHex.R,LatinoHex.G,LatinoHex.B)
            end
        end
    elseif Value == 4 then
        Value = Value + 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = LightskinHex
                v.LeftArmColor3 = LightskinHex
                v.LeftLegColor3 = LightskinHex
                v.RightArmColor3 = LightskinHex
                v.RightLegColor3 = LightskinHex
                v.TorsoColor3 = LightskinHex
                LocalColor.Value =(LightskinHex)
                Event:FireServer(LightskinHex.R,LightskinHex.G,LightskinHex.B)
            end
        end
    elseif Value == 5 then
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = BrownHex
                v.LeftArmColor3 = BrownHex
                v.LeftLegColor3 = BrownHex
                v.RightArmColor3 = BrownHex
                v.RightLegColor3 = BrownHex
                v.TorsoColor3 = BrownHex
                LocalColor.Value =(BrownHex)
                Event:FireServer(BrownHex.R,BrownHex.G,BrownHex.B)
            end
        end
    end
end)

PreviousButton.MouseButton1Click:Connect(function()
    if Value == 5 then
        Value = Value - 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = BrownHex
                v.LeftArmColor3 = BrownHex
                v.LeftLegColor3 = BrownHex
                v.RightArmColor3 = BrownHex
                v.RightLegColor3 = BrownHex
                v.TorsoColor3 = BrownHex
                LocalColor.Value =(BrownHex)
                Event:FireServer(BrownHex.R,BrownHex.G,BrownHex.B)
            end
        end
    elseif Value == 4 then
        Value = Value - 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = LightskinHex
                v.LeftArmColor3 = LightskinHex
                v.LeftLegColor3 = LightskinHex
                v.RightArmColor3 = LightskinHex
                v.RightLegColor3 = LightskinHex
                v.TorsoColor3 = LightskinHex
                LocalColor.Value =(LightskinHex)
                Event:FireServer(LightskinHex.R,LightskinHex.G,LightskinHex.B)
            end
        end
    elseif Value == 3 then
        Value = Value - 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = LatinoHex
                v.LeftArmColor3 = LatinoHex
                v.LeftLegColor3 = LatinoHex
                v.RightArmColor3 = LatinoHex
                v.RightLegColor3 = LatinoHex
                v.TorsoColor3 = LatinoHex
                LocalColor.Value =(LatinoHex)
                Event:FireServer(LatinoHex.R,LatinoHex.G,LatinoHex.B)
            end
        end
    elseif Value == 2 then
        Value = Value - 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = TanHex
                v.LeftArmColor3 = TanHex
                v.LeftLegColor3 = TanHex
                v.RightArmColor3 = TanHex
                v.RightLegColor3 = TanHex
                v.TorsoColor3 = TanHex
                LocalColor.Value =(TanHex)
                Event:FireServer(TanHex.R,TanHex.G,TanHex.B)
            end
        end
    elseif Value == 1 then
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = WhiteHex
                v.LeftArmColor3 = WhiteHex
                v.LeftLegColor3 = WhiteHex
                v.RightArmColor3 = WhiteHex
                v.RightLegColor3 = WhiteHex
                v.TorsoColor3 = WhiteHex
                LocalColor.Value =(WhiteHex)
                Event:FireServer(WhiteHex.R,WhiteHex.G,WhiteHex.B)
            end
        end
    end
end)

Script:

local Event = game.ReplicatedStorage.CharacterTraits.ColorChosen
local Brown = script.Brown.Value
local Latino = script.Latino.Value
local Lightskin = script.Lightskin.Value
local Tan = script.Tan.Value
local White = script.White.Value
Event.OnServerEvent:Connect(function(Player,R,G,B)
    local Color = Player.Classets.Color.Value
    print(R,G,B)
    print(Color3.new(R,G,B))
    if Color3.new(R,G,B) == Brown or Color3.new(R,G,B) == Latino or Color3.new(R,G,B) == Tan or Color3.new(R,G,B) == Lightskin or Color3.new(R,G,B) == White then
        local Character = Player.Character
        Color = Color3.new(R,G,B)
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = Color3.new(R,G,B)
                v.LeftArmColor3 = Color3.new(R,G,B)
                v.LeftLegColor3 = Color3.new(R,G,B)
                v.RightArmColor3 = Color3.new(R,G,B)
                v.RightLegColor3 = Color3.new(R,G,B)
                v.TorsoColor3 = Color3.new(R,G,B)
            end
        end
    else
        --game.ReplicatedStorage.ColorChosen:FireServer(204, 142, 105)
        Player:Kick("Bad "..Player.Name.." Bad. No")
        warn("Kicked "..Player.Name.." For Color:".. Color3.new(R,G,B))
    end
end)

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
4 years ago

Here's a concept you should understand. Color3.new() takes values from 0-1, however you're passing numbers obviously greater than 1. You're thinking of Color3.new(204/255, 142/255, 105/255). In that case, you should use Color3.fromRGB(R,G,B) to use the full 255 numbers that you're seeking. Feel free to read up some more about this on the wiki. I did not read your 100+ line code, but I can tell that you're misunderstood on Color3.new(). Hope this clarifies! Feel free to comment

0
thanks mate i was starting to do a bunch of math with 255 because i tried using fromRGB before when i was only sending over the color3 values and that gave me the wrong result which happens to be the one im getting now again after reworking the script a little but i went back and changed it to fromRBG with the RGB values and it works fine somehow Donut792 216 — 4y
0
what i ended up doing was just muliplying them by 255 and setting fromRGB like that Donut792 216 — 4y
0
Ah! Well, now you know! Shawnyg 4330 — 4y
Ad

Answer this question