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

Color3 value gets set to 0,0,0. How do I fix this?

Asked by 6 years ago
Edited 6 years ago

I'm probably making an obvious mistake here, but I've tried lots of different routes to try and solve this problem, none of which have worked.

My script is:

local colourSave = game:GetService("DataStoreService"):GetDataStore("vehicleStats")
local key = ""
local Colour = Color3.new(127/255,127/255,127/255)

game.Players.PlayerAdded:connect(function(plr)
    key = "player_"..plr.UserId
    local initCheck = colourSave:GetAsync(key)
        if initCheck == nil then
            colourSave:SetAsync(key,tostring(Colour))
        end
    wait(1)
        for i, v in pairs(game.Workspace.ViewModel.Ranger.Body.Paint:GetChildren()) do
            v.Color = Color3.new(colourSave:GetAsync(key))
        end
            print(Color3.new(colourSave:GetAsync(key))) --debug
end)

game.ReplicatedStorage.vehicleStats.flashColour.OnServerEvent:connect(function(player, colour)
    colourSave:SetAsync(key,tostring(colour))
end)

The "colour" parameter received from the flashColour remote event looks something like this: 0.84532, 0.23536, 0.012463

I'm not sure what I'm doing wrong, so if anyone could help me with this, I'd greatly appreciate it.

0
Why are you dividing 127 by 255? RequiredModule 38 — 6y
1
Based on the research I've done, it seems that Color3 accepts decimal values between 0.0 and 1.0, so I thought it would make sense to set up the Colour variable that way. KeylessPlayz 8 — 6y
0
You're storing the string "0.84532, 0.23536, 0.012463" into your datastore. Try converting this back into a color via Color3.new("0.84532, 0.23536, 0.012463"), which is what you're doing right now, and see what color you're generating. XAXA 1569 — 6y
0
Instead of saving the string, save the color as a table {Colour.r, Colour.g, Colour.b}, and convert this back to a color using Color3.new(unpack({Your saved table}). XAXA 1569 — 6y
0
That worked perfectly, thanks! KeylessPlayz 8 — 6y

Answer this question