local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Strength = Instance.new("NumberValue", leaderstats)
Strength.Name = "Strength"
Strength.Value = 1
local Exp = Instance.new("NumberValue", leaderstats)
Exp.Name = "Exp"
Exp.Value = 0
local RequiredExp = Instance.new("NumberValue", player)
RequiredExp.Name = "RequiredExp"
RequiredExp.Value = Strength.Value * 100
Exp.Changed:Connect(function(Changed)
if Exp.Value >= RequiredExp.Value then
Exp.Value = 0
Strength.Value += 1
RequiredExp.Value = Strength.Value * 100
end
end)
local playerUserId = "Player"..player.UserId
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
ViggxGood
(DevViggx)
February 13, 2022, 10:37pm
#2
What exactly are you trying to do here? Because right now it looks like you just wrapped it in a pcall and did nothing more with it. If you want the data to go into the player you have to check if the pcall was a success or not then after that add the wanted data into the player.
Not sure if that is what you had a problem with but I am guessing it is.
im a new scripter i dont know what im really doing
Ndawqz
(l_IoveQuantixDev)
February 13, 2022, 10:39pm
#4
ViggxGood
(DevViggx)
February 13, 2022, 10:41pm
#5
Try and use this, this will print the data you have saved if you have saved something.
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Strength = Instance.new("NumberValue", leaderstats)
Strength.Name = "Strength"
Strength.Value = 1
local Exp = Instance.new("NumberValue", leaderstats)
Exp.Name = "Exp"
Exp.Value = 0
local RequiredExp = Instance.new("NumberValue", player)
RequiredExp.Name = "RequiredExp"
RequiredExp.Value = Strength.Value * 100
Exp.Changed:Connect(function(Changed)
if Exp.Value >= RequiredExp.Value then
Exp.Value = 0
Strength.Value += 1
RequiredExp.Value = Strength.Value * 100
end
end)
local playerUserId = "Player"..player.UserId
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
print(data)
end
end)
This here won’t save or load your data but it will print out whatever you have saved
Confused as to how this is relevant to the discussion.
1 Like
ViggxGood
(DevViggx)
February 13, 2022, 10:45pm
#8
Try this, not the best one every but from here you can try and learn I guess…
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Strength = Instance.new("NumberValue", leaderstats)
Strength.Name = "Strength"
Strength.Value = 1
local Exp = Instance.new("NumberValue", leaderstats)
Exp.Name = "Exp"
Exp.Value = 0
local RequiredExp = Instance.new("NumberValue", player)
RequiredExp.Name = "RequiredExp"
RequiredExp.Value = Strength.Value * 100
Exp.Changed:Connect(function(Changed)
if Exp.Value >= RequiredExp.Value then
Exp.Value = 0
Strength.Value += 1
RequiredExp.Value = Strength.Value * 100
end
end)
local playerUserId = "Player"..player.UserId
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
Strength.Value = data[1]
Exp.Value = data[2]
RequiredExp.Value = data[3]
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local tosave = {}
local leader = player.leaderstats
local strength = leader.Strength
local exp = leader.Exp
local expReq = player.RequiredExp
tosave[strength.Value, exp.Value, expReq.Value]
myDataStore:SetAsync("Player_"player.UserId, tosave)
end)
i got so many errors from that script
ViggxGood
(DevViggx)
February 13, 2022, 10:46pm
#10
I never tested it. Can you show me the errors
ViggxGood
(DevViggx)
February 13, 2022, 10:47pm
#11
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Strength = Instance.new("NumberValue", leaderstats)
Strength.Name = "Strength"
Strength.Value = 1
local Exp = Instance.new("NumberValue", leaderstats)
Exp.Name = "Exp"
Exp.Value = 0
local RequiredExp = Instance.new("NumberValue", player)
RequiredExp.Name = "RequiredExp"
RequiredExp.Value = Strength.Value * 100
Exp.Changed:Connect(function(Changed)
if Exp.Value >= RequiredExp.Value then
Exp.Value = 0
Strength.Value += 1
RequiredExp.Value = Strength.Value * 100
end
end)
local playerUserId = "Player"..player.UserId
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
Strength.Value = data[1]
Exp.Value = data[2]
RequiredExp.Value = data[3]
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local tosave = {}
local leader = player.leaderstats
local strength = leader.Strength
local exp = leader.Exp
local expReq = player.RequiredExp
tosave[strength.Value, exp.Value, expReq.Value]
myDataStore:SetAsync("Player"..player.UserId, tosave)
end)