-
I want to achieve that my datastore is working correctly without any data leaks or kicking for no reason.
-
My issue is that sometimes the player gets kicked in middle of playing the game with a data error.
-
I have no idea what the problem is because I’m not really that of a specific when it comes to creating datastores.
This is the Datastore’s Code
--local Players = game:GetService("Players")
local serverscriptservice = game:GetService("ServerScriptService")
local manager = require(script.Parent:WaitForChild("Manager"))
local Template = require(script.Parent:WaitForChild("Template"))
local ProfileService = require(script.Parent:WaitForChild("ProfileService"))
local ProfileStore = ProfileService.GetProfileStore("Gamu_Data2",Template)
local function leaderstats(player : Player)
local profile = manager.Profiles[player]
if not profile then return end
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local DataFolder = Instance.new("Folder")
DataFolder.Parent = player
DataFolder.Name = "DataFolder"
local Bounty = Instance.new("NumberValue")
Bounty.Name = "Bounty"
Bounty.Parent = leaderstats
Bounty.Value = profile.Data.Bounty
local Beli = Instance.new("NumberValue")
Beli.Name = "Beli"
Beli.Parent = DataFolder
Beli.Value = profile.Data.Beli
local Strength = Instance.new("NumberValue")
Strength.Name = "StrengthLevel"
Strength.Parent = DataFolder
Strength.Value = profile.Data.Strength
local Defense = Instance.new("NumberValue")
Defense.Name = "DefenseLevel"
Defense.Parent = DataFolder
Defense.Value = profile.Data.Defense
local Sword = Instance.new("NumberValue")
Sword.Name = "SwordLevel"
Sword.Parent = DataFolder
Sword.Value = profile.Data.Sword
local Gun = Instance.new("NumberValue")
Gun.Name = "GunLevel"
Gun.Parent = DataFolder
Gun.Value = profile.Data.Gun
local Haki = Instance.new("NumberValue")
Haki.Name = "HakiLevel"
Haki.Parent = DataFolder
Haki.Value = profile.Data.Haki
--STATS--
local expfolder = Instance.new("Folder")
expfolder.Parent = DataFolder
expfolder.Name = "EXPFolder"
local HakiEXP = Instance.new("NumberValue")
HakiEXP.Name = "HakiEXP"
HakiEXP.Parent = expfolder
HakiEXP.Value = profile.Data.HakiEXP
local StrengthEXP = Instance.new("NumberValue")
StrengthEXP.Name = "StrengthEXP"
StrengthEXP.Parent = expfolder
StrengthEXP.Value = profile.Data.StrengthEXP
local DefenseEXP = Instance.new("NumberValue")
DefenseEXP.Name = "DefenseEXP"
DefenseEXP.Parent = expfolder
DefenseEXP.Value = profile.Data.DefenseEXP
local SwordEXP = Instance.new("NumberValue")
SwordEXP.Name = "SwordEXP"
SwordEXP.Parent = expfolder
SwordEXP.Value = profile.Data.SwordEXP
local GunEXP = Instance.new("NumberValue")
GunEXP.Name = "GunEXP"
GunEXP.Parent = expfolder
GunEXP.Value = profile.Data.GunEXP
--STATS--
--MAX STATS--
local HakiMaxEXP = Instance.new("NumberValue")
HakiMaxEXP.Name = "HakiMaxEXP"
HakiMaxEXP.Parent = expfolder
HakiMaxEXP.Value = profile.Data.HakiMaxEXP
local StrengthMaxEXP = Instance.new("NumberValue")
StrengthMaxEXP.Name = "StrengthMaxEXP"
StrengthMaxEXP.Parent = expfolder
StrengthMaxEXP.Value = profile.Data.StrengthMaxEXP
local DefenseMaxEXP = Instance.new("NumberValue")
DefenseMaxEXP.Name = "DefenseMaxEXP"
DefenseMaxEXP.Parent = expfolder
DefenseMaxEXP.Value = profile.Data.DefenseMaxEXP
local SwordMaxEXP = Instance.new("NumberValue")
SwordMaxEXP.Name = "SwordMaxEXP"
SwordMaxEXP.Parent = expfolder
SwordMaxEXP.Value = profile.Data.SwordMaxEXP
local GunMaxEXP = Instance.new("NumberValue")
GunMaxEXP.Name = "GunMaxEXP"
GunMaxEXP.Parent = expfolder
GunMaxEXP.Value = profile.Data.GunMaxEXP
--MAX STATS--
--DevilFruit--
local DevilFruit = Instance.new("NumberValue")
DevilFruit.Name = "DevilFruit"
DevilFruit.Parent = DataFolder
DevilFruit.Value = profile.Data.DevilFruit
--DevilFruit--
end
local function lvlupeffect(chr,color)
local sound = script:WaitForChild("LVLSFX"):Clone()
sound.Parent = chr:FindFirstChild("HumanoidRootPart")
sound:Play()
local effect = game:GetService("ReplicatedStorage"):FindFirstChild("ParticleFolder"):FindFirstChild("LVLUP"):WaitForChild("Attachment"):Clone()
game:GetService("Debris"):AddItem(sound,3)
effect.Parent = chr:FindFirstChild("HumanoidRootPart")
effect.p1.Color = color
effect.p2.Color = color
effect.p1:Emit(20)
effect.p2:Emit(20)
end
local function PlayerAdded(player : Player)
local Profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if Profile == nil then
player:Kick("Data Failed To Load(REJOIN!)")
return
end
Profile:AddUserId(player.UserId)
Profile:Reconcile()
Profile:ListenToRelease(function()
manager.Profiles[player] = nil
player:Kick("Data Failed To Load(REJOIN!)")
end)
if player:IsDescendantOf(Players) == true then
manager.Profiles[player] = Profile
leaderstats(player)
else
Profile:Release()
end
local datafolder = player:WaitForChild("DataFolder")
local EXPFolder = datafolder:WaitForChild("EXPFolder")
local StrengthLevel = datafolder:WaitForChild("StrengthLevel")
local StrengthEXP = EXPFolder:WaitForChild("StrengthEXP")
local StrengthMaxEXP = EXPFolder:WaitForChild("StrengthMaxEXP")
StrengthEXP:GetPropertyChangedSignal("Value"):Connect(function()
if StrengthEXP.Value >= StrengthMaxEXP.Value then
local sum = StrengthEXP.Value-StrengthMaxEXP.Value
print(StrengthEXP.Value.." "..StrengthMaxEXP.Value)
Profile.Data.StrengthEXP = sum
Profile.Data.StrengthMaxEXP *= 1.175
Profile.Data.Strength += 1
StrengthLevel.Value += 1
StrengthEXP.Value = StrengthEXP.Value-StrengthMaxEXP.Value
StrengthMaxEXP.Value += 10
local chr = player.Character
if chr ~= nil then
lvlupeffect(chr,ColorSequence.new(Color3.fromRGB(255, 0, 0)))
end
end
end)
-- DEFENSE
local DefenseLevel = datafolder:WaitForChild("DefenseLevel")
local DefenseEXP = EXPFolder:WaitForChild("DefenseEXP")
local DefenseMaxEXP = EXPFolder:WaitForChild("DefenseMaxEXP")
DefenseEXP:GetPropertyChangedSignal("Value"):Connect(function()
if DefenseEXP.Value >= DefenseMaxEXP.Value then
local sum = StrengthEXP.Value-StrengthMaxEXP.Value
Profile.Data.DefenseEXP = sum
Profile.Data.DefenseMaxEXP *= 1.175
Profile.Data.Defense += 1
DefenseLevel.Value += 1
DefenseEXP.Value = DefenseEXP.Value-DefenseMaxEXP.Value
DefenseMaxEXP.Value += 10
local chr = player.Character
if chr ~= nil then
lvlupeffect(chr,ColorSequence.new(Color3.fromRGB(0, 255, 0)))
end
end
end)
end
for _,player in Players:GetPlayers() do
task.spawn(PlayerAdded,player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player : Player)
local Profile = manager.Profiles[player]
if not Profile then return end
Profile:Release()
end)
local function Addstats(player,stat,amount)
local Profile = manager.Profiles[player]
if not Profile then return end
print("Added "..amount.."To".."Stat is now "..stat.Value)
Profile.Data[stat.Name] += amount
stat.Value = Profile.Data[stat.Name]
end
game:GetService("ReplicatedStorage"):WaitForChild("AddStatus").Event:Connect(Addstats)
Please i would be so happy if someone could find the problem for me.