Bem… Eu refiz um module script que ia fazer uma “metatable” para quando um jogador entrasse no jogo, ele ia adcionar o nome do jogador a esta metatable ou table mesmo e tambem iria colocar uma outra table que contia os stats de um jogador dentro da nova table que seria a do player que entrasse no jogo:
The module script:
function players.addPlayer(name)
players[name] = status
print(players)
end
And I also made a script that saves the player’s data:
local badge = game:GetService("BadgeService")
local clans = require(game.ReplicatedStorage.Clans)
local plrData = require(game.ReplicatedStorage.plrData)
local dataStore = game:GetService("DataStoreService")
local dataGroup = dataStore:GetDataStore("PlayerStats")
local events = game.ReplicatedStorage:WaitForChild("Events")
local alrJoined = false
game.Players.PlayerAdded:Connect(function(player)
local key = player.UserId
if alrJoined == true then
dataGroup:GetAsync(key)
print("Loaded!")
end
if alrJoined == false then
plrData.addPlayer(player.Name)
plrData.SetClanAndNenCategory(player.Name)
plrData.Contruct(player.Name)
----------
----------
local plrInfoTxt = player.PlayerGui:WaitForChild("PlayerBar"):WaitForChild("PlayerInfo")
plrInfoTxt.Text = "(WIP) ,"..plrData[player.Name].Clan.."(WIP)"..", Potential: "..plrData[player.Name].Potential
----------
----------
local char = player.Character or player.Character:Wait()
local hum = char:WaitForChild("Humanoid")
hum.WalkSpeed = plrData[player.Name].Speed
hum.MaxHealth = plrData[player.Name].Defense
hum.Health = plrData[player.Name].Defense
----------
----------
local sucess,failed = pcall(function()
dataGroup:SetAsync(key,plrData[player.Name])
print("Saved!")
end)
if not sucess then
warn("Error!")
end
end
end)
The problem is that whenever I load or exit the game a message appears saying:
The data seems fine, can I see how the SetClanAndNenCategory and Construct methods interact with the data? They may be inserting invalid values
Doesn't relate to the error, but other stuff I noted
Since you’re setting it to the status table (which I’m assuming isn’t copied), everyone will have the same status table as their value:
-- example
local t1 = {k = 2, i = 3}
local t2 = t1
t2.k = 3
print(t1.k) --> prints '3' instead of '2'
You should do:
players[name] = table.clone(status)
You can just do GetAsync and check if the player’s data is nil to check if the player played the game before; the variable won’t do much because it will be set to false (by default) for every new server that is created. Also, since this is server sided, if the variable is ever set to true, it will be set to true for everyone else who also joins.
But the variable is never changed in the code? So that’s why I was confused
function players.Contruct(name)
players[name].Potential = math.random(1,100)
players[name].Speed = players[name].Speed + (players[name].Potential/15)
players[name].Strenght = players[name].Strenght + (players[name].Potential/10)
players[name].Defense = players[name].Defense + (players[name].Potential/1)
print(name..":"..players[name].Potential ," ",players[name].Speed ," ",players[name].Strenght," ",players[name].Defense)
end
function players.SetClanAndNenCategory(name)
local nenType = {
Enhancer = 60,
Emission = 60,
Transmutation = 60,
Manipulation = 60,
Conjuration = 60,
Specialist = 1,
}
local sum1 = 0
for _,values in pairs(nenType) do
sum1 = sum1 + values
end
local function nenCategory()
local clanV = Random.new():NextNumber(0,sum1)
for i,v in pairs(nenType) do
clanV = clanV - v
if clanV < 0 then
return i
end
end
end
players[name].NenCategory = nenCategory()
print("Your name type is"..players[name].NenCategory.."!")
local cc = {
Zoldyck = 1,
Kurta = 0.1,
Kreuger = 5,
Netero = 1,
Freecs = 1,
Todoroki = 0.5,
Hatake = 60,
Takano = 60,
Tsezguerra = 60,
Portor = 60,
Kimito = 60,
Sugerawa = 60,
Uchiha = 0.001,
}
local sum2 = 0
for _,values in pairs(cc) do
sum2 = sum2 + values
end
local function setClan()
local clanV = Random.new():NextNumber(0,sum2)
for i,v in pairs(cc) do
clanV = clanV - v
if clanV < 0 then
return i
end
end
end
players[name].Clan = setClan()
print("Your clan is "..players[name].Clan.."!")
if players[name].Clan == "Zoldyck" then
elseif players[name].Clan == "Kurta" then
elseif players[name].Clan == "Kreuger" then
elseif players[name].Clan == "Netero" then
elseif players[name].Clan == "Freecs" then
end
end
it sounds like you’re storing characters that aren’t allowed in a datastore. they only accept UTF-8 characters, which is a specific set of chars - are you doing something with Unicode?
as a side note, you’re literally doing nothing with the data you get, not even setting it to a variable or anything. have you not included something in the script? also i would use RemoteEvents for the changing of a PlayerGui, it’s not great practise to just modify the GUI from the server