Im making a sort of customization system and as you can see on the video, i made the first option where u customize the number on your back (sort of like football players shirts with the number and the name on the back).
The problem is, i dont know how to save the TextLabel’s Text (which is the number) when the player is leaving the game and then put the text saved when the player rejoins.
Here where is situated the SurfaceGui which inside there is the TextLabel:
I tried looking on youtube, here and even on the creator documentation for more info, but unfortunately i didnt find anything that could help me.
i tried do it on my own and i came up doing this:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TextLabelData")
local function saveTextLabel(player)
local character = player.Character
local surfaceGui = character.Torso:FindFirstChild("NameAndNumberBack")
local textLabel = surfaceGui:FindFirstChild("Number")
local success, err = pcall(function()
DataStore:SetAsync(player.UserId .. "_TextLabelValue", textLabel.Text)
end)
if not success then
warn("Error saving data:", err)
end
end
local function loadTextLabel(player)
local character = player.Character
local surfaceGui = character.Torso:FindFirstChild("NameAndNumberBack")
local textLabel = surfaceGui:FindFirstChild("Number")
local success, savedValue = pcall(function()
return DataStore:GetAsync(player.UserId .. "_TextLabelValue")
end)
if success and savedValue then
textLabel.Text = savedValue
end
player.CharacterRemoving:Connect(function()
saveTextLabel(player)
end)
end
game:GetService("Players").PlayerAdded:Connect(function(player)
loadTextLabel(player)
end)
game:GetService("Players").PlayerRemoving:Connect(function(player)
saveTextLabel(player)
end)
Even tho, this script i made doesnt work and it doesnt give any errors in the output.
So how can i save the TextLabel’s Text?