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

How do i save a player's value with Filtering Enabled?

When filtering enabled is not enabled, it saves the player's data perfectly, but when filtering enabled is on, it doesn't. Do i have to use remote events to update the player's data value or something? Please give me an example.

This is the data store script :

local DSService = game:GetService('DataStoreService'):GetDataStore('DBSRData')
game.Players.PlayerAdded:connect(function(p)
	wait(2.5)
	-- Define variables
	thing = game.ServerStorage.Data:Clone()
	thing.Parent = p
	local uniquekey = 'id-'..p.userId
	local names = {}
	
	for i, v in pairs(p.Data:GetChildren()) do
		table.insert(names, v.Name)
	end
	
	-- GetAsync
	local GetSaved = DSService:GetAsync(uniquekey)
	if GetSaved then
		for i, v in pairs(p.Data:GetChildren()) do
			v.Value = GetSaved[i]
		end
		
		for i=1, #GetSaved do
				print(i .. ": " .. names[i] .. " = " .. tostring(GetSaved[i]))
		end
	else
		local NumbersForSaving = {}
			for i, v in pairs(p.Data:GetChildren()) do
				table.insert(NumbersForSaving, v.Value)
			end
		DSService:SetAsync(uniquekey, NumbersForSaving)
	end
end)

game.Players.PlayerRemoving:connect(function(p)
	local uniquekey = 'id-'..p.userId
	local Savetable = {}
		for i, v in pairs(p.Data:GetChildren()) do
			table.insert(Savetable, v.Value)
		end
		
	DSService:SetAsync(uniquekey, Savetable)			
end)

2 comments

0

What happens when you turn FE on? Does the client change any values?

0

In the game i have, you click a button to add +15 to your strength value and when i leave and rejoin it doesnt save. When FE is off, it works fine

1 answer

✓ Accepted answer

Right so your problem here is that you are only changing your values for the client-side. FE means client changes don't replicate to the server, so every time you add 15 the server still sees it as 0 because it hasn't replicated.

To change it, you would need to do something like

Client

local RemoteEvent = game.ReplicatedStorage['RemoteEvent']
RemoteEvent:FireServer(15)

Server

local RemoteEvent = game.ReplicatedStorage['RemoteEvent']
RemoteEvent.OnServerEvent:connect(function(p, number)
	--add "number" to whatever value you want
end)

You can read more about RemoteEvents here

Hope this helped!

1 comment

0

Ohhk, so in the server script, on line 3 do i write how the players data changes? like if it changes then it saves or something like that?

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