Help with Datastore

I’ve checked tutorials about datastore, all of them have positive feedback and are trusted and stuff, but when I try the tutorial and then try changing the intvalue, it doesn’t save in the next session. I have Enable Studio Access to API Services on, but it still doesn’t work. Does anyone know why?

1 Like

What is your code? I can’t really get any information off text

2 Likes

Make sure you are controlling server not client

local DSS = game:GetService("DataStoreService")
local thisDataStore = DSS:GetDataStore("PixelBootsDataStore")
local players = game:GetService("Players")
local runService = game:GetService("RunService")

local canRunInStudio = true --change this to whatever you'd like

local defaultData = 2 --set this to whatever you'd like

players.PlayerAdded:Connect(function(plr)
	local pixelBoots = Instance.new("NumberValue")
	pixelBoots.Name = "PixelBoots"
	pixelBoots.Parent = plr
	local data
	local success, response = pcall(function()
		data = thisDataStore:GetAsync(plr.UserId)
	end)
	if success then
		if data then
			pixelBoots.Value = data.PixelBoots
		else
			pixelBoots.Value = defaultData
		end
		plr:SetAttribute("HasLoadedDataStore", true)
	end
end)
players.PlayerRemoving:Connect(function(plr)
	local pixelBoots = plr.PixelBoots
	local data = {pixelBoots.Value}
	local hadLoadedAttribute = plr:GetAttribute("HasLoadedDataStore")
	local success, response = pcall(function()
		if (not runService:IsStudio() or canRunInStudio == true) and hadLoadedAttribute == true then
			thisDataStore:SetAsync(plr.UserId, data)
		end
	end)
end)

Credits to @hatespine for giving me this code.

2 Likes

Is editing an intvalue during a session okay?

Is this in studio only or both?

I haven’t tested it in the game yet, I’m doing it in studio.

Datastores don’t see client changes so change to server when testing

How do you do that in Roblox Studio?

This may be your issue, try removing this. (first part)

Click on the “Client” button on the home tab it should have the image of a computer

image

If you’re on the Client mode, changes you make won’t replicate to the server.

Thank you so much! It works. Also, do you know how to edit it from local scripts and scripts? Do you use script.Player.LocalPlayer?

I don’t think you can edit datastores from local scripts

Then how do you perform something like this?

local devilArmor = script.Parent
local frame = game.Lighting
local blocks = frame:WaitForChild("PixelBoots")

devilArmor.Text = blocks.Value

blocks.Changed:Connect(function(newValue)
	devilArmor.Text = newValue
end)

Unless you send a remote event to the server which is highly unsecured unless you protect it

1 Like

I don’t understand what you want to do

So, how do you make a secure way of performing it?

So, basically, this script makes it so that it displays the integer value in a TextButton in a GUI.

Unless you its for admin commands it’s pretty hard unless you do check for a user or a item or a value.