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

how would i save colours for multiple parts and multiple houses?

Asked by
MHaven1 159
5 years ago
Edited 5 years ago

i want to save colours for multiple houses and each house has multiple houses how would i save them? i know how to save them the long way so like

--when player leaves--
local colourdatastore =game:GetService("DataStoreService"):GetDataStore("Colour")
colourdatastore:SetAsync(player.UserId..":wallcolour:")

--when player enters--
local getwallcolour= colourdatastore:GetAsync(player.userId..":WallColour")
if wallcolour == nil then
    wallcolour.Value = Brickcolor.new("Black")
else
    wallcolour.Value = getwallcolour
end

iis there a easier way to save them? because the way i know will take a long time and alot of space, anything will be great TY.

0
Use a table to store them. DinozCreates 1070 — 5y
0
yes i can use a table but its for multiple houes and each house can have multiple colours MHaven1 159 — 5y
0
how would i access it from a table tho? it comes out nil when i do v.Value MHaven1 159 — 5y
0
I dont understand your point, using a table would still be much more efficient. You could save every house and every color into one table, and only require 1 data store. DinozCreates 1070 — 5y
0
Hmm, let me see if i can whip something up. Hopefully its what you mean. DinozCreates 1070 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Hopefully this is more or less what you were looking for, the way I structured it you'd either have to make the strings here or child them in a folder and clone them into the player.

local colourdatastore =game:GetService("DataStoreService"):GetDataStore("Colour")

function savefiles(player)
    local SaveTable = {
        wallcolor1 = player.House1.wallcolor1.Value,
        wallcolor2 = player.House1.wallcolor2.Value,
        wallcolor3 = player.House1.wallcolor3.Value,
        wallcolor4 = player.House1.wallcolor4.Value
    }
    return SaveTable
end
local save = savefiles(player)

local H1 = player.House1
local saved = colourdatastore:GetAsync(player.userId)

game.Players.PlayerAdded:Connect(function(player)--load players info
    function loadsave(player, save)
        H1.wallcolor1.Value = saved.wallcolor1
        H1.wallcolor2.Value = saved.wallcolor2
        H1.wallcolor3.Value = saved.wallcolor3
        H1.wallcolor4.Value = saved.wallcolor4
    end
    function pullthedata()
        --this is where you'll need to make something to grab the color values from the strings and convert the brick color into corresponding color
    end
end)

function savefunc(player)
    colourdatastore:SetAsync(player.userId,save)
end

game.Players.PlayerRemoving:Connect(savefunc)--save players info on d/c
0
Thanks bro. MHaven1 159 — 5y
Ad

Answer this question