Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

HELP DATASTORE IS STILL NOT WORKING AFTER FOUR DAYS. HELP?

everything prints but it does not save

local DS = game:GetService("DataStoreService"):GetDataStore("StorageThing")
game.Players.PlayerAdded:Connect(function(plr)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    stats.Parent = plr
    
    local Soul = Instance.new("IntValue")
    Soul.Name = "Screams"
    Soul.Parent = stats
    Soul.Value = DS:GetAsync(plr.UserId)
    
    DS:SetAsync(plr.UserId,Soul.Value)
    
    game:BindToClose(function()
	    print("saving data")
	    DS:SetAsync(plr.UserId,plr.leaderstats.Screams.Value)
	    print(plr.Name.."'s data has been Big save")
    end)
    
    game.Players.PlayerRemoving:Connect(function()
	    print("saving data")
	    DS:SetAsync(plr.UserId,plr.leaderstats.Screams.Value)
	    print(plr.Name.."'s data has been Big save")
	end)
end)

3 comments

0

well,because the plr variable is declared in a scope different from the BindToClose function and PlayerRemoving event

0

i answered this couple days ago lol

0

Not sure why you're setting the value immediately after getting it, and if the lines runs without errors the value did save, print to debug what values you're actually saving. Please don't all caps your post.

1 answer

✓ Accepted answer

I left a comment on your previous post in regards to this script. Everything within this script does work properly, it seems like you may have just not been using it correctly.

First thing you will want to do is make sure that for testing purposes, by going to the page of your place, click one the "..." next to your game's name. Then go to "Configure this Game", once you are here it should bring you to the Basic Settings tab. Right above the blue Save button, make sure you tick the box next to "Enable Studio Access to API Services".

Doing the above will allow you to use a Data Store while you're in studio.

Another thing you haven't told is how you're testing this and where you are altering data from. When it comes to Data Stores, it will only take information that is found in the Server. If you are altering the information only on the client side then that won't work.

To show this works if you want to replicate it yourself, once you've made sure that you have Access to API enabled go ahead and launch studio. Inside of the ServerScriptService add the script you've posted with no altercations. At the top of studio go to your "Test" tab and run a Local Server with 1 Player.

That will open two new windows, one that is the server and one that is the client. From the server window you can go ahead and change the Screams to any value you want. Once you hit enter you can see the printed message that it's saved properly. You can also click on the Client window and see the proper number on the leaderstats. Give it 1-2 seconds for the information to be sent to ROBLOX and close down the Server Window. (Closing the server window will close the Client Window by default)

Go ahead and re-open the Local Server by doing the same steps above, once your client loads in you will see all of your data.

You need to make sure that when you alter the data, it is properly done on the server, otherwise it's not saving proper information. It seems like you were altering on the Client, so when the store saved it pulled 0 from the Server rather then the # you had on the Client.

This is a bit of a read but hopefully it helps you understand what happend!

This discussion is preserved as it was. New answers, comments, and votes are closed.