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

My DataStore script won't work when I turn on FE, fixes?

I don't know where's the problem. The script works fine with one of my games that doesn't have FE.

local datastore = game:GetService("DataStoreService"):GetDataStore("GameStore")
game.Players.PlayerAdded:connect(function(player)

	local leaderstats = Instance.new("IntValue")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local xd = Instance.new("IntValue") 
	xd.Name = "BUX" 
	xd.Parent = leaderstats
	xd.Value = 0
	
	local qe = Instance.new("IntValue") 
	qe.Name = "Hexoton"
	qe.Parent = leaderstats
	qe.Value = 0
	
	
	local key = "user-" .. player.userId
	
	local storeditems = datastore:GetAsync(key)
	if storeditems then
		xd.Value = storeditems[1] 
		qe.Value = storeditems[2]
	else
		local items = {xd.Value, qe.Value}
		datastore:SetAsync(key, items)
	end
end)

game.Players.PlayerRemoving:connect(function(player)
	local items = {player.leaderstats.BUX.Value, player.leaderstats.Hexoton.Value }
	local key = "user-" .. player.userId
	
	datastore:SetAsync(key, items)
	end)

2 comments

0

To me, there is nothing wrong with it. Does it give you any errors?

0

Is it in local script or script?

1 answer

You are only changing your values for the client-side. FE means client changes don't replicate to the server, so when the player's data val changes, it doesn't save because it isn't replicated.

Making a script in the client making a remote event, Then in the server script connect the remote event by using OnServerEvent. For Ex: RemoteEvent.OnServerEvent:connect(function(p, number) then add "number" to whatever value you want. Message back if you have any error's.

3 comments

0

Where's 'client'?

0

Client is the player

0

Didn't really get it

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