Hi! So I wanna make it when the players join, the saved data will be loaded. Here’s my script
local DS = game:GetService("DataStoreService"):GetDataStore("Data")
game.Players.PlayerAdded:Connect(function(player)
local playerUserId = player.UserId
local folder = Instance.new("Folder",player)
folder.Name = "Slot1"
local c = game.StarterPlayer.StarterCharacter:Clone()
c.Parent = folder
DS:GetAsync("key", {
mesh = player.Slot1.StarterCharacter.Hair.Mesh.MeshId,
ofs = player.Slot1.StarterCharacter.Hair.OffsetValue.Value,
s = player.Slot1.StarterCharacter.Hair.ScaleValue.Value,
hcR = player.Slot1.StarterCharacter.Hair.Color.R,
hcG = player.Slot1.StarterCharacter.Hair.Color.G,
hcB = player.Slot1.StarterCharacter.Hair.Color.B,
scR = player.Slot1.StarterCharacter["Body Colors"].HeadColor.r,
scG = player.Slot1.StarterCharacter["Body Colors"].HeadColor.g,
scB = player.Slot1.StarterCharacter["Body Colors"].HeadColor.b,
shirt = player.Slot1.StarterCharacter.Clothing.ShirtTemplate,
pants = player.Slot1.StarterCharacter.Pants.PantsTemplate,
class = player.Slot1.StarterCharacter.Class.Value,
code = player.Slot1.StarterCharacter.CodeName.Value,
})
local data = DS:GetAsync("key")
-- player.Character.Class.Value = data.class
--[[player.Slot1.StarterCharacter.Hair.Mesh.MeshId = data.mesh --This is the part I want to load
player.Slot1.StarterCharacter.Hair.Mesh.Offset = data.ofs
player.Slot1.StarterCharacter.Hair.Mesh.Scale = data.s
player.Slot1.StarterCharacter.Hair.Color.R = data.hcR
player.Slot1.StarterCharacter.Hair.Color.G = data.hcG
player.Slot1.StarterCharacter.Hair.Color.B = data.hcB
player.Slot1.StarterCharacter["Body Colors"].HeadColor.r = data.scR
player.Slot1.StarterCharacter["Body Colors"].HeadColor.g = data.scG
player.Slot1.StarterCharacter["Body Colors"].HeadColor.b = data.scB
player.Slot1.StarterCharacter.Clothing.ShirtTemplate = data.shirt
player.Slot1.StarterCharacter.Clothing.ShirtTemplate = data.pants
player.Slot1.StarterCharacter.Class.Value = data.class
player.Slot1.StarterCharacter.CodeName.Value = data.code ]]
end)
game.StarterGui.InsertedObjects.Slot1.MouseButton1Up:Connect(function(player)
DS:SetAsync("key",player.UserId)
end)
local function onShutDown()
local RunService = game:GetService("RunService")
if RunService:IsStudio() then
wait(2)
else
local finished = Instance.new("BindableEvent")
local allPlayers = game:GetService("Players"):GetPlayers()
local leftPlayers = #allPlayers
for _,player in ipairs(allPlayers) do
coroutine.wrap(function()
DS:SetAsync("key",player.UserId)
leftPlayers -= 1
if leftPlayers == 0 then
finished:Fire()
end
end)
end
finished.Event:Wait()
end
end
game.Players.PlayerRemoving:Connect(function(player)
DS:SetAsync("key",player.UserId)
onShutDown()
end)
When I’m trying to load the data, I get an error, that these aren’t valid numbers, either if I do it with a string value.
Error:
“Attempt to index number with mesh”
Can someone help me? If I remove that lines, I get no error.
