Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Datastore server script not saving when leaving the game?

Asked by
hoth7 45
3 years ago

So basically I'm trying to save a value called "Electric", this value will be stored between a value of 0 and 1. There's no issue with the console, and it even says it's working. However, I've found that it loads correctly but it doesn't save correctly. There's no blatant issue here and I've also tested it on Roblox, same result, it doesn't work. (also please don't be one of those people who are like oOoOoo use bind to close)

Script:


local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore2") game.Players.PlayerAdded:Connect(function(player) local Origin = Instance.new("Folder") Origin.Name = "Origin" Origin.Parent = player local Electric = Instance.new("IntValue") Electric.Name = "Electric" Electric.Parent = Origin local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId.."-Electric") end) if success then Electric.Value = data print("Hothkinstroy is best coder :O") else print("HOTHKINSTROY SUCKS AT CODING LOL HE CANT CODE SOMETHING THIS SIMPLE") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() myDataStore:SetAsync(player.UserId.."-Electric", player.Origin.Electric.Value) end) if success then print("Hothkinstroy best coder :o") else print("HOTHKINSTROY IS THE WORST CODER HE CANT EVEN CODE A BASIC SCRIPT THIS SIMPLE LOL") warn(errormessage) end end)
0
seems fine, kinda sus. WINDOWS10XPRO 438 — 3y
0
Try to test this with two players because sometimes player removing doesn't work or doesn't continue because the server closes before the function could ever run gamingwithjbthepro 76 — 3y
0
I tried it, still doesnt work. hoth7 45 — 3y
0
Are you ever changing the Intvalues? if so, where? mariohead13 129 — 3y

Answer this question