Btw, don’t use the YouTube tutorials, they don’t tell you how to do it right. Just copy the example code the guy gives, and then go on from there figuring it out. Also, just save their data when they leave when using this.
Don’t think throwing something at someone and saying to figure it out will help me, the code looks like spaghetti, I dont want to waste 5 hours trying to figure it out.
Well, if dealing with the data loss of SetAsync when your game reaches high traffic and having over 300 players’ weight on your shoulders, then that’s your choice.
You don’t need to be super advanced at all, just copy his example code, paste it in a test place, and go on from there. Trust me, I have a game that hit a peak of 2k players and an average of 800, and I wish I implemented profile service a lot more ealier.
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
-- This code only runs when the player's character is added.
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
-- Do player removing stuff here.
end)
local getSuccess, currentGold = pcall(function()
return goldStore:GetAsync(playerUserID)
end)
if getSuccess then
print("hi")
player.Character:WaitForChild("StatsLocal").LocalPlayerStrength.Value = PLRstrength
end
it doesent set the value to the number
all 3 his printed
local DataStoreService = game:GetService("DataStoreService")
local goldStore = DataStoreService:GetDataStore("PLRstrength")
game.Players.PlayerAdded:Connect(function(player)
print("hI")
local playerUserId = "Player_"..player.UserId
local getSuccess, currentGold = pcall(function()
return goldStore:GetAsync(playerUserId)
end)
if getSuccess then
print("hi")
player.Character:WaitForChild("StatsLocal").LocalPlayerStrength.Value = currentGold
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local PLRstrength = player.Character:WaitForChild("StatsLocal").LocalPlayerStrength.Value
goldStore:SetAsync(playerUserId, PLRstrength)
print("Hi")
end)
Also, make sure the “studio access to API services” setting is enabled if it isn’t already.
you need to keep the value in the player not the character it is destroyed when they player leaves the game instantly or keep it in an attribute on the player – the best practice is keeping a table in your save script of each players data then update as it changes that way no matter what you have a table to save then you set it to nil after the save