[Solved] Client-Side Datastore not Saving Data

I’m trying to make a system to automatically buy weapons that you buy in a UI. The saving works in another script that I’m using but not this one.

Here is the script for auto-buying:

local weapons = {}
for _, v in pairs(script.Parent:GetChildren()) do
	if v.ClassName == 'TextButton' then
		table.insert(weapons, v.Weapon.Name) -- Adds the weapon name to the table
	end
end

wait()

for _, wName in pairs(weapons) do
	wait()
	local data = game.ReplicatedStorage.Datastore.GetData:InvokeServer('PrimaryWeaponsDataStore', tostring(game.Players.LocalPlayer.UserId)..';'..wName) -- Fetches the data
	if data then -- If data is found...
		local w = script.Parent:FindFirstChild(wName)
		w.CostLabel.Text = 'Owned'
		w.CostLabel.TextColor3 = Color3.new(0.172549, 0.815686, 0.0588235)
		w.CostLabel.TestStrokeColor3 = Color3.new(0.0666667, 0.34902, 0.0235294)
		w.Owned.Value = true
	end
end

Here is the script linked to the remote function:

GetData.OnServerInvoke = function(player, DataStoreName, Key)
	return DataStore:GetDataStore(DataStoreName):GetAsync(Key)
end

The text is not changing to “Owned”

I would like to know what the problem may be and maybe how to fix it.

Thank you for helping

Try this:

local weapons = {}
for _, v in pairs(script.Parent:GetChildren()) do
    if v.ClassName == 'TextButton' then
        table.insert(weapons, v.Weapon.Name) -- Adds the weapon name to the table
    end
end

wait()

for _, wName in pairs(weapons) do
    wait()
    local data = game.ReplicatedStorage.Datastore.GetData:InvokeServer('PrimaryWeaponsDataStore', tostring(game.Players.LocalPlayer.UserId)..';'..wName) -- Fetches the data
    if data then -- If data is found...
        local w = script.Parent:FindFirstChild(wName)
        w.CostLabel.Text = 'Owned'
        w.CostLabel.TextColor3 = Color3.new(0.172549, 0.815686, 0.0588235)

        w.CostLabel.TextStrokeColor3 = Color3.new(0.0666667, 0.34902, 0.0235294) -- Corrected line

        w.Owned.Value = true
    end
end

The error happened because you put TestStroke, not Text

Yeah, I realized that earlier which is why the title says “[Solved]”. Thank you anyways :smile:

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