Hello, I am working on a datastore and am using a method I have never tried before to achieve it. Basically, when the game needs to save the player’s data, a server script fires a remote event to a local script which is a descendant of the player. It tells the local script what is being saved, and the local script sends another remote event to the server script with the information it needs. However, the server script can’t seem to get the right information. When I print the value being sent from the local script (in this case, the player’s money), I get a number value. However, when I print this same value from the server script, it prints the player’s username. I honestly have no clue what’s going on here, any help is appreciated!
Local Script:
local values = game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("Values")
game.ReplicatedStorage:WaitForChild("dataToClient").OnClientEvent:Connect(function(fTokens)
print("Recieved!")
values:WaitForChild("dataValue").Value = fTokens
end)
game.ReplicatedStorage:WaitForChild("savingConnector").OnClientEvent:Connect(function()
local fTokens = values:WaitForChild("dataValue").Value
local info = {
fTokens = fTokens;
message = "Hello, there.";
}
game.ReplicatedStorage:WaitForChild("dataToServer"):FireServer(info)
end)
--The server script is recieving the information wrong, fTokens is confirmed to be a number value in this script, but in the server script it becomes the player's username.
Server Script:
local DS = game:GetService("DataStoreService")
local dataScript = require(game.ReplicatedStorage:WaitForChild("savingDataTest"))
local VERSION = "1.0.0"
local playerStuff = {}
game.Players.PlayerAdded:Connect(function(Player : Player)
playerStuff[Player.UserId] = dataScript.new(Player) --Doesn't create an entirely new save key, just adds a key (new or used) to that server's metatable for later use.
playerStuff[Player.UserId]:LoadData() --Uses the player's key to load their data
--game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("Values"):WaitForChild("dataValue").Value = playerStuff[Player.UserId].Data.FrenzyTokens
print(playerStuff[Player.UserId].Data.FrenzyTokens)
local fTokens = playerStuff[Player.UserId].Data.FrenzyTokens
game.ReplicatedStorage:WaitForChild("dataToClient"):FireClient(Player, fTokens)
end)
game.Players.PlayerRemoving:Connect(function(Player : Player)
playerStuff[Player.UserId]:SaveData()
end)
workspace.saveBtn.save.Triggered:Connect(function(Player : Player)
game.ReplicatedStorage:WaitForChild("savingConnector"):FireClient(Player)
game.ReplicatedStorage:WaitForChild("dataToServer").OnServerEvent:Connect(function(info)
print(info[0])
playerStuff[Player.UserId]:SaveData(info.fTokens)
end)
end)