I try so hard but my datastore just can’t seem to work here
local datastoreservice = game:GetService("DataStoreService")
local ds = datastoreservice:GetDataStore("Data4") --
game.Players.PlayerAdded:Connect(function(player)
if not player:FindFirstChild("Data") then
local Folder = Instance.new("Folder" ,player)
Folder.Name = "Data"
end
local Data = player:WaitForChild("Data" ,5)
local DevilFruit = Instance.new("StringValue",Data)
DevilFruit.Name = "DevilFruit"
--==Currency variables==--
local Currency = Instance.new("IntValue",Data)
Currency.Name = "Beli"
local Gems = Instance.new("IntValue",Data)
Gems.Name = "Gems"
--==Stats variables==--
local TotalLevel = Instance.new("IntValue",Data)
TotalLevel.Name = "TotalLevel"
local Defense = Instance.new("IntValue",Data)
Defense.Name = "Defense"
local Strength = Instance.new("IntValue",Data)
Strength.Name = "Strength"
local Agility = Instance.new("IntValue",Data)
Agility.Name = "Agility"
local DefenseExp = Instance.new("IntValue",Data)
DefenseExp.Name = "DefenseExp"
local StrengthExp = Instance.new("IntValue",Data)
StrengthExp.Name = "StrengthExp"
local AgilityExp = Instance.new("IntValue",Data)
AgilityExp.Name = "AgilityExp"
local disabled = Instance.new("BoolValue",player)
disabled.Value = false
disabled.Name = "Disabled" --- disables combat
print("Loading Data...")
local getdata = ds:GetAsync(player.UserId)
if getdata ~= nil then ---/// NUMBERS IN ORDER IN HERE!
DevilFruit.Value = getdata[1]
Currency.Value = getdata[2]
TotalLevel.Value = getdata[3]
Gems.Value = getdata[4]
Strength.Value = getdata[5]
Defense.Value = getdata[6]
Agility.Value = getdata[7]
DefenseExp.Value = getdata[8]
StrengthExp.Value = getdata[9]
AgilityExp.Value = getdata[10]
else ---//// IF YOU DONT HAVE DATA YET!
DevilFruit.Value = "None"
Currency.Value = 100
TotalLevel.Value = 4
Gems.Value = 5
Strength.Value = 1
Defense.Value = 1
Agility.Value = 1
DefenseExp.Value = 0
StrengthExp.Value = 0
AgilityExp.Value = 0
end
print("Data loaded succesfully!")
DevilFruit.Changed:Connect(function()
local savedata = {}
for i,v in pairs(player.Data:GetChildren()) do
table.insert(savedata,v.Value)
end
ds:SetAsync(player.UserId,savedata)
if DevilFruit.Value == "None" then
print("no devilfruit")
else
local moves = game.Lighting.Fruits:WaitForChild(DevilFruit.Value.."_Moves")
moves.Parent = player.Character
print(DevilFruit.Value)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local savedata = {}
for i,v in pairs(player.Data:GetChildren()) do
table.insert(savedata,v.Value)
end
ds:SetAsync(player.UserId,savedata)
print(player.UserId)
print("Succesfully saved Data!")
end)