As the title says I have created a data store that, at the moment, only saves the players hair. For structure, I have a local script in a screen gui that allows the player to edit their appearance and when they save it sends the data via a remote event to the server script.
Now the problem, the data store works but I can’t figure out why the player wont spawn in with the hair accessory. Same thing if I were to try and configure a players face texture Id. Any help is appreciated.
Could you share the code you’re using for the server script and localscript? I do also recommend protecting the remotes to prevent datastore requests being backed up of exploiters spamming the remote
When entering the code into DF, remove the datastore key and name to avoid leaking it
This is the code that sends the players data(their hair) to the datastore:
saveBtn.MouseButton1Click:Connect(function()
-- Get the player's current hair (if they have one equipped)
local currentHair = plr.Character:FindFirstChildOfClass("Accessory")
local hairName = currentHair and currentHair.Name or nil
-- Sending Data
DataEvent:FireServer(hairName)
plr.Character:SetPrimaryPartCFrame(workspace.SpawnLocation.CFrame)
camera.CameraType = Enum.CameraType.Custom
plr.Character.Humanoid.WalkSpeed = 16
plr.Character.Humanoid.JumpHeight = 7.5
_G.isInMenu = false
saveFrame.Visible = false
customizeFrame.Visible = false
end)
And this is the function that gets the players items:
local function GetPlayerItems(plr)
local plrUID = tostring(plr.UserId) -- Converting User ID
local char = plr.Character or plr.CharacterAdded:Wait()
local success, data = pcall(function()
return PlayerItems:GetAsync(plrUID)
end)
-- Initializing the table if it's not
if not success then
warn("Error retrieving data for", plr.Name)
data = {} --// Defaults data
elseif type(data) ~= "table" then
data = {}
end
print("Data loaded for", plr.Name, ":", data)
plr:SetAttribute("HairIndex", data.HairIndex or 1)
if data.Accessory then
local accessory = game.ReplicatedStorage.Accessories:FindFirstChild(data.Accessory)
if accessory then
local clonedAccessory = accessory:Clone()
clonedAccessory.Parent = char:WaitForChild("Head")
end
end
-- Save data when the player dies
char.Humanoid.Died:Connect(function()
local successSave, errorMsg = pcall(function()
PlayerItems:SetAsync(plrUID, {
HairIndex = plr:GetAttribute("HairIndex"),
Accessory = char:FindFirstChildOfClass("Accessory") and char:FindFirstChildOfClass("Accessory").Name or nil
})
end)
if successSave then
print("Data saved on death for", plr.Name)
else
warn("Failed to save data on death:", errorMsg)
end
end)
end
And again it does save it correctly and when I try and change the appearance it even saves the index value it just doesn’t apply it to the player itself.
Yea this is what I have tried, but it wouldn’t work. I did manage to fix it but placing the server script inside of the screen gui(not sure why I didn’t try that) but thanks anyways.