Okay I will try that Thanks So Much!
Have you turned on API Services and HTTP Requests?
Yes and this is in game too. I also turned it on in Roblox Studio
I am not really here for solving your problem, but @Ubiquitous_Creature I would recommend you not to spoon feed them with the whole scripts, if you do it for showing how to fix it, I would say you should write what you changed, and what was causing the problem.
Also, could you give your latest version of the script in one post, so its helpful for debugging? Also I don’t think requiring datastore2 with the Id gives you the latest version, the latest release can be found on the github release page: Release DataStore2 v1.3.0 · Kampfkarren/Roblox · GitHub
Okay. All that does not work is sometimes when a player rejoins in the game, there gold is 0. But when their gold changes from killing or from any activity from buying swords, the gold changes to what their value saved was. But to otehr people it is always saved. You just can not see your own gold in teh begginning.
local defaultValue = 100 --If player has no data then their gold will be set to this value
local DataStore2 = require(1936396537)
game.Players.PlayerAdded:Connect(function(player)
local goldData = DataStore2("Gold", player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local goldStat = Instance.new("IntValue", leaderstats)
goldStat.Name = "Gold"
local function UpdateStat()
goldStat.Value = goldData:Get(defaultValue)
end
goldData:OnUpdate(function()
UpdateStat()
end)
goldStat.Changed:Connect(function()
if goldStat.Value > goldData:Get() then
goldData:Set(goldStat.Value)
end
end)
goldStat.Value = goldData:Get(defaultValue)
end)
As far as I know, you should Combine all your keys at the beginning and also as I said get the latest version of DataStore2. The thing is you don’t need to do it that way I believe.
You can just do:
local defaultValue = 100 --If player has no data then their gold will be set to this value
local DataStore2 = require(1936396537)
DataStore2.Combine("DATA", "Gold")
game.Players.PlayerAdded:Connect(function(player)
local goldData = DataStore2("Gold", player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local goldStat = Instance.new("IntValue", leaderstats)
goldStat.Name = "Gold"
goldStat.Value = goldData:Get(defaultValue)--Initially you need to get the value from datastore/default value if data isn't there for the player.
local function UpdateStat(value) --the OnUpdate function passes the updated value, so you don't need to run :Get again.
print(value)--Will print updated value.
end
goldStat.Changed:Connect(function()
goldData:Set(goldStat.Value) -- You were checking if the goldStat value is more than datastore value, what if goldStat was decreased? It won't even update.
end)
goldData:OnUpdate(UpdateStat) --You were running this function in another anonymous function inside, which is not needed.
end)
Also get the updated version of datastore2, it can be that you have a outdated version?
That script does not work either. Does not save. I think it saves kind of, but not partially, When I use @Ubiquitous_Creature script it just saves but has the problem I said before.
You probably have to change the keys, also please read my whole reply properly and do what all I said side by side too.
Yeah I saw. But when a player buys something like before the gold would automatically show right when they did osmething to it.
First of all, are you changing the gold from localscript / server sided script?
Also have you changed the datastore key, and got the up-to-date version of Datastore2?
It is a regular script in ServerScript Service, and I will try to see if there is a new datastore key
So would there be a way to fix this?