Datastore not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Pretty new to scripting.
I am trying to save a numbervalue: “damage” on the datastore, but when I print the value, it shows nil.

  1. What is the issue? Include screenshots / videos if possible!

This is my script; sorry for the screenshot overload
image





  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have changed the name of the datastore as to make a new one, but the same problem kept occurring. I think the issue might occur because I changed the values in the default playerData assigned to new player: the damage and health instances used to say “0” before I figured out what I wanted them to be.

If that was the issue, though, I would have expected it to disappear when I made a new database with the new values from the start, but it didn’t.

-- This is an example Lua code block

Are you changing the value of the damage instance? It seems the values on sessionData are updated only when the instance changes value rather than updating it to a default value (ex. 0) when you create it.

Yes, I change the damage instance when players upgrade their stats. And as I am testing the datastore script I change the value by clicking a button, but the sessiondata doesn’t seem to notice

I’m guessing your script is printing “damage changed” in the output, yes?

This is the script for changing the damage instance:


When I use it, the game prints out that the damage is changing (line 140) and tells me the new value, but when I end the test and start is up again, the game print nil again

This MouseClick is located on the server then, correct? Try in a normal Roblox game rather than on Studio and see if anything changes.

Yes, it’s in a serverscript. I will test it on Roblox now

I am testing it on Roblox, but is there a quick way to print the message in the chat so that I can see if it works?

If you’re using the new TextChatService:

local TCS = game:GetService("TextChatService");
TCS.TextChannels.RBXGeneral:DisplaySystemMessage(msg); -- replace with your message
1 Like

Okay I tested it. When I change the damage on roblox and return to studio, the damage seem to be saved on the datastore. Could this be an issue that only I will experience, because I started out by typing the wrong values on the default playerdata?

If the version on Roblox is the same as the one in Roblox Studio then no that’s not the issue, it’s most likely something to do with Roblox Studio not registering PlayerRemoving/BindToClose properly. When you leave the game on Studio, do you see the prints from your playerLeaving function?

1 Like

No, I don’t. Wow, hadn’t even noticed that.

From now on, I’ll test the game on Roblox before losing my mind over it :smiley: Thanks for the help, everything seems to work now!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.