DataStore Not Working with API Service Enabled (The Script is not Work for Roblox Studio ONLY)

local DSS = game:GetService("DataStoreService")
local bloodpointDS = DSS:GetDataStore("bloodpointDS")

game.Players.PlayerAdded:Connect(function(plr)

	local folder = Instance.new("Folder", plr)
	folder.Name = "Monetary"							--Bloodpoints

	local BP = Instance.new("IntValue", folder)			--Bloodpoints
	BP.Name = "Bloodpoints"
	BP.Value = bloodpointDS:GetAsync(plr.UserId) or 0


	BP.Changed:Connect(function()

		bloodpointDS:SetAsync(plr.UserId, BP.Value)
		print("DataSaved!")
		print(plr.Name .. "'s bloodpoints: " .. BP.Value)
	end)

end)

This is my database but it is not working. Can someone help me?

P.S. There also dont have any outputs.

1 Like

plr.UserId is a number while the key parameter is supposed to be a string. I also don’t recommend saving the player’s data every time a stat is changed, you can do it when they leave the server using game.Players.PlayerRemoving.

1 Like

use GetPropertyChangedSignal instead of changed

local DSS = game:GetService("DataStoreService")
local bloodpointDS = DSS:GetDataStore("bloodpointDS")

game.Players.PlayerAdded:Connect(function(plr)

	local folder = Instance.new("Folder", plr)
	folder.Name = "Monetary"							--Bloodpoints

	local BP = Instance.new("IntValue", folder)			--Bloodpoints
	BP.Name = "Bloodpoints"
	BP.Value = bloodpointDS:GetAsync(plr.UserId) or 0

	BP:GetPropertyChangedSignal("Value"):Connect(function()
		local Saved = pcall(function()
			bloodpointDS:SetAsync(plr.UserId, BP.Value)
		end)
		
		if Saved then
			print("DataSaved!")
		end
		
		print(plr.Name .. "'s bloodpoints: " .. BP.Value)
	end)
end)

I have done this but It is not working too

It does not work for me too. Why? Actually, I have watched a lot of youtube tutorials and even now I can remember the codes but I still cant make a working datastore. :disappointed_relieved::disappointed_relieved::disappointed_relieved:

1 Like

what did you even enable?

your script works fine
https://gyazo.com/b04aa3334237cbfd0204e37d49ce6d37

are you getting any errors or output from the script?

no output, no errors, nothing about this

I have made leaderstats datastore one year ago, it worked, but im not making this in this place.

without datastore in the search part nothing also?
and try to toggle off the API service there and save it then go back in and toggle it back on then republish to the server and try it again

had someone else earlier today with same issue kinda thinking its an issue with api or something

[IMAGE DELETED]

Second: I have toggled it off and toggle it back and republished.

I have investigated the problem for a while, and I have found one question. Why does the script only not work for me??? I put this script into another place and it is not working (I have checked the API service has opened)

Does someone have an idea that what happened?

where is the script located? and its for sure not disabled?

ServerScriptService, and I m sure it is abled

maybe I should test it in the real game first.

Everyone, I have due with this, it is a Roblox studio bug. When I am testing it in Roblox, it works properly.

And also, I want to thank all of you for answering my questions, especially @Nyonic.

1 Like

Just some additional information to anyone who comes across this:

This is not exactly a studio bug. When changing the API services enabled setting from the website, it won’t update to studio.

This is why you should change the setting from the studio game settings page instead.

Well, for this, I have changed the API setting both on the website and the game setting. Therefore, it is a bug i think.