Storing player data from a local script

So i have my leaderstats stored in a gui and in the player.
But i want the server to also acces the leaderstats, the leaderstats are handled by a localscript so you can’t get them via the server.

I also thought about use a remote event, but sending playerdata/leaderstats trough a remote event gives exploiters the chance to change it easily .

so is there any way for me to save playerdata to the datastores without having to use a remote event.

1 Like

What do the leaderstats contain?

This is not safe at all. You really should store it on the server, ina folder somewhere (like replicated storage or the player) and then have the local script read data. Everything on the client is changeable by exploiters. So when we are talking about using remotes and passing information, You shouldn’t need to, as you should use it on the server.

the highscore of the player, so that isn’t good if exploiters have acces to it

How is the highscore calculated? Or, rather, how does a player get a highscore?

i have my data store on the server in serverscript service, but i want to save my data from the clients gui to the server without using a remote event.

I have the localscript read the leaderstats from the player inside the player leaderstats. but any changes made to the leaderstats can’t be seen by the server bc it is changed by the client

Your going to have to use some sort of remote. My idea, is to Use a remote function. Whenever a score is calculated, use a Remote function and fire it in the server. The client then preforms the math and get the score, and uses ‘return’ to the value. While this isn’t bulletproof, it’s atleast better then a remote event sending the value via the server

The server shouldn’t invoke the client because it can yield forever.

So i have a startpart and i use .Magnitude calculate how far away the player is from the beginning

local startpart = game.Workspace.MainParts.StartPartTP
local player = game.Players.LocalPlayer
local startevent = game.ReplicatedStorage.Events.StartGame

local numberspinner = require(game.ReplicatedStorage.NumberSpinner)
local RealTimeScoreSpinner = numberspinner.fromGuiObject(script.Parent.RealTimeScore)
RealTimeScoreSpinner.Decimals = 0 
--Spinner.Prefix = "Score: " 
RealTimeScoreSpinner.Prefix = ""
RealTimeScoreSpinner.Duration = 0.25
RealTimeScoreSpinner.TextScaled = false
RealTimeScoreSpinner.Parent = script.Parent


local function round(n)
	return math.floor(n + 0.5)
end

startevent.Event:Connect(function()
	local RealTimeScore = script.Parent.RealTimeScore
	local HighScore = script.Parent.HighScore
	local HighScoreStats = player:WaitForChild("Stats").HighScore
	HighScore.Text = HighScoreStats.Value
	while wait(.1) do
		if not player.Character:FindFirstChild("Humanoid") then
		else
			RealTimeScoreSpinner.Value = round((startpart.Position - player.Character:GetPivot().Position).Magnitude)
			RealTimeScore.Text = round((startpart.Position - player.Character:GetPivot().Position).Magnitude)
			--warn(HighScore)
			--warn(RealTimeScore.Text)
			
			if tonumber(HighScore.Text) < tonumber(RealTimeScore.Text) then
				HighScoreStats.Value = RealTimeScore.Text
				HighScore.Text = HighScoreStats.Value
				warn("true "  .. HighScore.Text .. " " .. RealTimeScore.Text)
			else
				warn("false "  .. HighScore.Text .. " " .. RealTimeScore.Text)
			end
		end
	end
end)

Yes however you can handle this and drop it.

You could do this on server. Then there is no need to send data and the server can just save it.

1 Like

I didn’t know this. How is this possible?

I’m not on my computer right now. But it’s a couple more lines to handle this. If it takes longer then a certain amount of time, you then remove the request and try again if possible. But this is the best you can do which is better then just having it spilt out errors

But again, I would want to calculate this on the server and not rely on the client

so the server sends a message to the playergui asking for the “highscore leaderstat” and the client sends it back to the server using “return” and then the server saves it?

How do you remove a request though? I get you’re not on your computer so you prob can’t answer that.

Yes, if you have to.

But again, I would want to calculate this on the server if possible. If you absolutely have to, then yes, but please reconsider just storing the value on the server

I’m pretty sure you can use a connection and check. And then if you don’t get a result, you disconnect the connection to the function, so it stops running so it stops infinity yielding

i use (startpart.Position - player.Character:GetPivot().Position).Magnitude idk if that can be done on the server bc it starts to calculate after the client receives a .event from a bindable even from the “press start” button.

and if its possible then idk how it would handle multiple players at the same time?

What? - The problem with passing data through a RE is NOT the usage of the RE itself, rather, it is that you are passing Client data: information that is manipulable by the client, thus the player, to the server to store it.

Seen a visual hack? - Well, these work because you are modifying the data YOU see. If you let hackers pass that data to the server, then what you are doing essentially is giving them a way of making visual hacks real.

thats why, i asked if there is a solution to not use a remote event