I am unsure how this is too large to store into Roblox’s DataStores - it’s trying to say I’m saving an instance for some reason. However, all I am storing are strings and numbers - am I not supposed to do that? I have looked at the different topics like this and they aren’t helping.
Here is the table I am saving because I want to sort the values by names instead of using table[x : num]:
-- This for lazy people who just came to copy & paste, not to learn the code...
-- // Assigning variables //
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("ProgressDataStore") -- This can be changed to whatever you want
local function saveData(player) -- The functions that saves data
player.PlayerGui:WaitForChild("FetchData"):FireClient(player)
local tableToSave = workspace.FetchedData.OnServerEvent:Wait()
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, tableToSave) -- Save the data with the player UserId, and the table we wanna save
end)
if success then -- If the data has been saved
print("Data has been saved!")
else -- Else if the save failed
warn(err)
print("Data hasn't been saved!")
end
end
game.Players.PlayerAdded:Connect(function(player) -- When a player joins the game
local data -- We will define the data here so we can use it later, this data is the table we saved
local success, err = pcall(function()
data = dataStore:GetAsync(player.UserId) -- Get the data from the datastore
end)
if success and data then -- If there were no errors and player loaded the data
print(unpack(data))
player:WaitForChild("leaderstats").Mode.Value = data["Mode"]
player.PlayerGui:WaitForChild("DataLoadClient"):FireClient(player, data)
else -- The player didn't load in the data, and probably is a new player
print("The player has no data!") -- The default will be set to 0
end
end)
game.ReplicatedStorage.CheckpointCredits.OnServerEvent:Connect(function(player)
local success, err = pcall(function()
saveData(player) -- Save the data
end)
if success then
print("Data has been saved")
else
warn(err)
print("Data has not been saved!")
end
end)
game.Players.PlayerRemoving:Connect(function(player) -- When a player leaves
local success, err = pcall(function()
saveData(player) -- Save the data
end)
if success then
print("Data has been saved")
else
print("Data has not been saved!")
end
--[[task.wait(1)
workspace.PlayerDataPersist.PlayerData:FindFirstChild(player.Name):Destroy()
workspace.PlayerDataPersist.leaderstats:FindFirstChild(player.Name):Destroy()]]
end)
game:BindToClose(function() -- When the server shuts down
for _, player in pairs(game.Players:GetPlayers()) do -- Loop through all the players
local success, err = pcall(function()
saveData(player) -- Save the data
end)
if success then
print("Data has been saved")
else
print("Data has not been saved!")
end
end
end)
The server tells the client to give it the data and then it attempts to save it.
I also don’t think it’s a Studio issue as DataStores usually are the same between Studio and the game client as it loads my credits correctly either way.
Sorry for the misunderstanding, I meant print tableToSave from the saveData function (on the server). Check this value to ensure everything was passed over correctly to the server.
You are using the RemoteEvent incorrectly here, OnServerEvent will have the Player as the first Argument, when you yield until a event fires, it will give you the data that came from the event, which in this case, the Player, instead of any relevant data from your DataStore, as you havent given it any other data to get.
Also, please do not let the Client have a say in what is saved by the DataStore, especially with important data like this, Exploiters are able to Manipulate the Client and add whatever data they want to it.
No, that’s not the issue. The issue is that I’m using local x = workspace.Event.OnServerEvent:Wait() which only returns the player, while local x,y = workspace.Event.OnServerEvent:Wait() returns both the player and the table. How am I using the RemoteEvent incorrectly if I have done something similar?
It’s an obby, I don’t care if they cheat. You can either play legitimately or not + what is the reason for cheating in a game like this?
Most I would do is store the day the player first joined and then kick them if they gain too many credits. Other than that, I don’t really care that much. There aren’t even fighting aspects either, so…
They could set their credits using the remoteevent in small amounts anyways so I could just monitor it depending on the max credits you should be able to gain at the last (30th) checkpoint.
Securing your game would mean they actually have to try in the game, which can have players play the game more often, if they can get everything without playing the game, whats the point of playing the game? Exploiters just make your game not fun, making nobody want to play it
Correction, why wouldn’t they?
What is the reason for cheating in a competition?
Whats the reason for cheating in a Exam?
Whats the reason for cheating in Sports?
Nobody says this because they dont want the players to not have fun, they say this to make it fun, and to keep players, its very important, and should be disregarded because “its just an obby”.
I don’t need to secure it if cheating isn’t an issue. Nobody cares if you’re flying around and giving yourself infinite lives because it doesn’t impact anyone else. It’s basically a singleplayer game where you can talk to other people.