I understand how datastores work but the only thing I do not understand how to save a string. Here is my script and what I am trying to accomplish:
local dataStoreService = game:GetService("DataStoreService")
local chatcolorData = dataStoreService:GetDataStore("2013Color")
function onEnter(player)
local o = Instance.new("StringValue",player)
o.Parent = player
o.Name = "ChatColor"
o.Value = chatcolorData:GetAsync(player.UserId) or "Red"
end
function onLeave(player)
if player:FindFirstChild("ChatColor") then
chatcolorData:SetAsync( player.UserId, player.ChatColor.Value )
end
end
game.Players.PlayerAdded:Connect(onEnter)
game.Players.PlayerRemoving:Connect(onLeave)
To save a string value, you need to save the property that you need if I’m correct.
For example, let’s create a scenario where you require more than 1 property.
You can simply do this:
local table = {
script.Value.Value
script.Value.Parent
}
To reference it do this:
table[1]
table[2]
Unfortunately data stores cannot save instances and I assume it’s because of major crashes that will occur because of that. What’s fortunate though is that it can save properties since they are values. It’s able to save any values such as int values.