Maybe you’re add value is set to 0 ?
the value are increasing but it just wont save also add is set to 1
You are loading players data under an infinite loop it will never run !
what do i do also i checked datastore editor it only creates the datastore but wont assign the data
Just change this: local success, errorMessage = pcall(dataStore.SetAsync, dataStore, player.UserId, tableToSave)
With local success, errorMessage = pcall(function() dataStore:SetAsync(player.UserId, tableToSave) end)
Replace the function you’re running when the player added event fire by this :
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Strenght= Instance.new("IntValue")
Strenght.Name = "Strenght"
Strenght.Parent = leaderstats
Strenght.Value = 0
local Defense= Instance.new("IntValue")
Defense.Name = "Defense"
Defense.Parent = leaderstats
Defense.Value = 0
local KI= Instance.new("IntValue")
KI.Name = "KI"
KI.Parent = leaderstats
KI.Value = 0
local Physic= Instance.new("IntValue")
Physic.Name = "Physic"
Physic.Parent = leaderstats
Physic.Value = 0
local TP= Instance.new("IntValue")
TP.Name = "TP"
TP.Parent = leaderstats
TP.Value = 0
local smulti= Instance.new("IntValue") --Creates an IntValue
smulti.Name = "smulti" --Sets IntValue name to "deaths" (If you change this make sure you change all of them)
smulti.Parent = leaderstats --Puts the IntValue under the "leaderstats" folder
smulti.Value = 1 --Gives the IntValue Value to start off with
local dmulti= Instance.new("IntValue") --Creates an IntValue
dmulti.Name = "dmulti" --Sets IntValue name to "deaths" (If you change this make sure you change all of them)
dmulti.Parent = leaderstats --Puts the IntValue under the "leaderstats" folder
dmulti.Value = 1 --Gives the IntValue Value to start off with
local pmulti= Instance.new("IntValue") --Creates an IntValue
pmulti.Name = "pmulti" --Sets IntValue name to "deaths" (If you change this make sure you change all of them)
pmulti.Parent = leaderstats --Puts the IntValue under the "leaderstats" folder
pmulti.Value = 1 --Gives the IntValue Value to start off with
local kmulti= Instance.new("IntValue") --Creates an IntValue
kmulti.Name = "kmulti" --Sets IntValue name to "deaths" (If you change this make sure you change all of them)
kmulti.Parent = leaderstats --Puts the IntValue under the "leaderstats" folder
kmulti.Value = 1 --Gives the IntValue Value to start off with
local uis = game:GetService("UserInputService")
local data
local success, errorMessage = pcall(function()
data = dataStore:GetAsync(player.UserId)
end)
if success and data then
Strenght.Value = data[1]
Defense.Value = data[2]
KI.Value = data[3]
Physic.Value = data[4]
TP.Value = data[5]
else
print("The Player has no Data!")
warn(errorMessage)
end
local add = game:GetService("ReplicatedStorage").Add.Value
local db = false
uis.InputBegan:Connect(function(input, gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.F then
if db == false then
db = true
Strenght.Value=Strenght.Value + add.Value * smulti.Value
wait(0.2)
db = false
end
end
if input.KeyCode == Enum.KeyCode.Q then
if db == false then
db = true
KI.Value=KI.Value + add.Value * kmulti.Value
wait(0.2)
db = false
end
end
if input.KeyCode == Enum.KeyCode.V then
if db == false then
db = true
Defense.Value=Defense.Value + add.Value * dmulti.Value
wait(0.2)
db = false
end
end
if input.KeyCode == Enum.KeyCode.Y then
if db == false then
db = true
Physic.Value=Physic.Value + add.Value * pmulti.Value
wait(0.2)
db = false
end
end
end)
while wait(0.2) do
TP.Value = Strenght.Value + Physic.Value + KI.Value + Defense.Value
end
end)
Basicaly if you do this it will print nothing :
local t = 0
while wait(0.2) do
t += 1
end
print("it will never print")
where do i change the script since uis doesnt work in server script also im pretty sure you cant create leaderstats in local script
I’ll provide you an exemple wait only a few minuts !
okay ill wait till u provide an example
I finished so this script will only set, save and load strenght value but it is an exemple :
Server
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("PlayerData")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEventStrenght = ReplicatedStorage.s
local Add = ReplicatedStorage.Add
RemoteEventStrenght.OnServerEvent:Connect(function(Player)
local StrenghtMultiplicator = Player.leaderstats.smulti
local Strenght = Player.leaderstats.Strenght
Strenght.Value = Strenght.Value + Add.Value * StrenghtMultiplicator.Value
end)
Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Strenght= Instance.new("IntValue")
Strenght.Name = "Strenght"
Strenght.Parent = Leaderstats
Strenght.Value = 0
local Success, Data = pcall(function()
return PlayerData:GetAsync(Player.UserId)
end)
if Success and Data then
for v, ValueInstance in pairs(Leaderstats:GetChildren()) do
if ValueInstance:IsA("ValueBase") then
ValueInstance.Value = Data[ValueInstance.Name]
end
end
else
warn(Player.Name.." is a new player or there was an error while loading his data !")
end
end)
Players.PlayerRemoving:Connect(function(Player)
local Data = {}
for v, ValueInstance in pairs(Player.leaderstats:GetChildren()) do
if ValueInstance:IsA("ValueBase") then
Data[ValueInstance.Name] = ValueInstance.Value
end
end
local Success = pcall(function()
PlayerData:SetAsync(Player.UserId, Data)
end)
if Success then
print("Data of "..Player.Name.." has been saved successfuly !")
else
warn("Data of "..Player.Name.." hasn't been saved successfuly !")
end
end)
Client
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent)
if Input.KeyCode == Enum.KeyCode.F then
ReplicatedStorage.s:FireServer()
end
end)
I hope that was helpful !
Make sure You keep bindToClose! i just helped another guy with the same issue lol
have a good day
could i add others stuff like defense KI etc
i edited ur code fixed 2 errors and now it works thanks!
added more stats too in the script
in the server script
for v, ValueInstance in pairs(Player.leaderstats) do
if ValueInstance:IsA("ValueBase") then
Data[ValueInstance.Name] = ValueInstance.Value
end
end
this part had error
for v, ValueInstance in pairs(Player.leaderstats) do
the Player.leaderstats had error since the error said table expected so i changed it to this
local mainstats = Player.MainStats
for v, ValueInstance in pairs(mainstats) do
if ValueInstance:IsA("ValueBase") then
Data[ValueInstance.Name] = ValueInstance.Value
end
end
Oh my bad you only have to do this :
for v, ValueInstance in pairs(Player.leaderstats:GetChildren()) do
can i use my version which i use now also idk how to make bindtoclose so ye
No you can’t since in my script I’m getting leaderstats children and I don’t understand what you want to make with bind to close ?