You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
saving data whenever the player leaves, or bindtoclose
What is the issue? Include screenshots / videos if possible!
iam trying to make it save the data, but its does not work , iam getting no errors
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes i follow totutiols on youtube
local Data = DataStore:GetDataStore("Data")
function playerJoined(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Power = Instance.new("NumberValue")
Power.Name = "Power"
Power.Parent = leaderstats
Power.Value = 15
local Rebirths = Instance.new("NumberValue")
Rebirths.Name = "Rebirths"
Rebirths.Parent = leaderstats
Rebirths.Value = 0
local MaxLine = Instance.new("NumberValue")
MaxLine.Parent = player
MaxLine.Name = "MaxLine"
MaxLine.Value = 100
local MutiPiler = Instance.new("NumberValue")
MutiPiler.Parent = player
MutiPiler.Name = "MutiPiler"
MutiPiler.Value = 1
local Speed = Instance.new("NumberValue")
Speed.Parent = player
Speed.Name = "Speed"
Speed.Value = 1
local NewData
local success, errormessage = pcall(function()
NewData = Data:SetAsync(player.UserId.. "Power", player.leaderstats.Power.Value)
end)
if success then
print("Success")
Power.Value = NewData
else
print("ERROR")
warn(errormessage)
end
end
function PlayerRemoving(player)
local success, errormessage = pcall(function()
Data:SetAsync(player.UserId.. "Power", player.leaderstats.Power.Value)
end)
if success then
print("success fully Saved")
else
print("Error")
warn(errormessage)
end
end
function BindToClose()
for _, player in ipairs(game.Players:GetPlayers()) do
local success, errormessage = pcall(function()
Data:SetAsync(player.UserId.. "Power", player.leaderstats.Power.Value)
end)
if success then
print("success fully Saved")
else
print("Error")
warn(errormessage)
end
end
end
game.Players.PlayerAdded:Connect(playerJoined)
game.Players.PlayerRemoving:Connect(PlayerRemoving)
game:BindToClose(BindToClose)
local DataStore = game:GetService("DataStoreService")
local Data = DataStore:GetDataStore("Data")
function playerJoined(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Power = Instance.new("NumberValue")
Power.Name = "Power"
Power.Parent = leaderstats
local Rebirths = Instance.new("NumberValue")
Rebirths.Name = "Rebirths"
Rebirths.Parent = leaderstats
local MaxLine = Instance.new("NumberValue")
MaxLine.Parent = player
MaxLine.Name = "MaxLine"
MaxLine.Value = 100
local MutiPiler = Instance.new("NumberValue")
MutiPiler.Parent = player
MutiPiler.Name = "MutiPiler"
MutiPiler.Value = 1
local Speed = Instance.new("NumberValue")
Speed.Parent = player
Speed.Name = "Speed"
Speed.Value = 1
local NewData
local data = Data:GetAsync(player.UserId)
if data then
Power.Value = data['Power']
Rebirths.Value = data['Rebirths']
else
Power.Value = 15
Rebirths.Value = 0
end
end
function CreateTable(player)
local Player_Stats = {}
for _, stat in pairs(player.leaderstats:GetChildren()) do
Player_Stats[stat.Name] = stat.Value
end
> Blockquote
return Player_Stats
end
function PlayerRemoving(player)
local Player_Stats = CreateTable(player)
local success, errormessage = pcall(function()
Data:SetAsync(player.UserId, Player_Stats)
end)
if success then
print("success fully Saved")
else
print("Error")
warn(errormessage)
end
end
function BindToClose()
for _, player in ipairs(game.Players:GetPlayers()) do
local Player_Stats = CreateTable(player)
local success, errormessage = pcall(function()
Data:SetAsync(player.UserId, Player_Stats)
end)
if success then
print("success fully Saved")
else
print("Error")
warn(errormessage)
end
end
end
game.Players.PlayerAdded:Connect(playerJoined)
game.Players.PlayerRemoving:Connect(PlayerRemoving)
game:BindToClose(BindToClose)