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

Why wont my data store save progress?

So I have been working on a game that is going to HEAVILY rely on data stores and it won't work. I have actually scrapped a project because of this and its making me so frustrated. Please help, add your username below so I can friend you and add you to the game, I just so dearly want this to work. So what we are focused on are CPods (capture pods) just as a test I added them and made a button click to add CPods. To make sure im clear, I meant to SET the Cpods as 5 not add, and when I click it and leave, it reverts back to its default (0)

CPods and datastore script

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
	leader = Instance.new("Folder",player)
	leader.Name = "leaderstats"
	local CPods = Instance.new("IntValue",leader)
	CPods.Name = "CPods"
	CPods.Value = ds:GetAsync(player.UserId) or 0
	ds:SetAsync(player.UserId, CPods.Value)
	CPods.Changed:connect(function()
		ds:SetAsync(player.UserId, CPods.Value)
	end)
end)


game.Players.PlayerRemoving:connect(function(player)
	ds:SetAsync(player.UserId, player,leader.CPods.Value)
end)

The script that sets the cpods as 5

Intro = script.Parent.Parent.controlFrame.Intro
Info = script.Parent.Parent.info.TextLabel
local Player = game.Players.LocalPlayer
local CPods = Player:WaitForChild('leaderstats'):WaitForChild('CPods')

script.Parent.MouseButton1Click:Connect(function()
	if Intro.Info.Text == ">Info" then
		Info.Text = "Press start to begin your adventure"
	else
			CPods.Value = 5
	end
end)

3 comments

0

is the first script a normal script? or local? If its a normal script, the problem is that the value is only changing to the client

0

There isn’t a third argument to :SetAsync(). Only the DataKey and it’s affiliated Data. Remove the ‘,’—which I assume is a mistake—and replace it with the intended dot operand (line 18.)

0

which script?

1 answer

✓ Accepted answer

the problem is that when you are setting Cpods to 5 is only on the client and the server cant see it so you can fixing with adding a remote event to ReplicatedStorage

Your local script should look like this

Intro = script.Parent.Parent.controlFrame.Intro
Info = script.Parent.Parent.info.TextLabel
local Event = game.ReplicatedStorage.RemoteEvent
local Player = game.Players.LocalPlayer
local CPods = Player:WaitForChild('leaderstats'):WaitForChild('CPods')

script.Parent.MouseButton1Click:Connect(function()
	if Intro.Info.Text == ">Info" then
		Info.Text = "Press start to begin your adventure" 
	else
		Event:FireServer(5)
	end
end)

The Script Should look like this

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
local Event = game.ReplicatedStorage.RemoteEvent

game.Players.PlayerAdded:connect(function(player)
    leader = Instance.new("Folder",player)
    leader.Name = "leaderstats"
    local CPods = Instance.new("IntValue",leader)
    CPods.Name = "CPods"
    CPods.Value = ds:GetAsync(player.UserId) or 0
end)

Event.OnServerEvent:Connect(function(Player ,Cpods)
	player,leaderstats.CPods.Value = Cpods
end)

game.Players.PlayerRemoving:connect(function(player)
    ds:SetAsync(player.UserId, player.leaderstats.CPods.Value)
end)

1 comment

0

I havent really been on lately but thats actually what I have been speculating on what would work. I will test tommorow when I have time

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