I’m assuming you’re testing the script in studio since you sent all the explorer pictures, have you made sure data store access is enabled in your studio on your specific experience?
Yes it certainly is, because like I have said before, the datastore works for everything but the damage and defense points. I’m going to try something, 1 second.
Throw in some prints if you haven’t already, what does data print when you join the game, another thing to try is (I HIGHLY doubt this is the problem but what have you got to lose) but use the proper way of parenting instances aka
local x = y
x.Parent = z
also print the values in the savedata function to see where they’re at.
I don’t know, maybe it’s one of the other scripts? I’ll link all connected scripts:
IncreaseDefenseHandler (in ServerScriptService):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Event = ReplicatedStorage:WaitForChild("Events"):WaitForChild("IncreaseDefense")
Event.OnServerEvent:Connect(function(player)
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.MaxHealth = humanoid.MaxHealth + 5
humanoid.Health = humanoid.Health + 5
end
end)
A localscript in a screengui:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("Events"):WaitForChild("IncreaseDefense")
local button = script.Parent
button.MouseButton1Click:Connect(function()
local player = Players.LocalPlayer
local statsFolder = player:WaitForChild("Stats")
if statsFolder then
local statPoints = statsFolder:WaitForChild("StatPoints")
if statPoints and statPoints.Value > 0 then
local defenseStat = statsFolder:WaitForChild("DefensePoints")
if defenseStat then
defenseStat.Value = defenseStat.Value + 5
statPoints.Value = statPoints.Value - 1
Event:FireServer(player)
else
warn("Failed to find ".. player .."'s defense stat")
end
end
end
end)
And here is the current script:
local dss = game:GetService("DataStoreService")
local savedLevelsDS = dss:GetDataStore("LevelsDSS")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("Events"):WaitForChild("IncreaseDefense")
function saveData(player)
pcall(function()
local level = player.Stats.Level.Value
local exp = player.Stats.Experience.Value
local statPoints = player.Stats.StatPoints.Value
local defensePoints = player.Stats.DefensePoints.Value
local damagePoints = player.Stats.DamagePoints.Value
savedLevelsDS:SetAsync(player.UserId .. "LevelsDSS", {level, exp, statPoints, defensePoints, damagePoints})
end)
end
game.Players.PlayerAdded:Connect(function(player)
local statsFolder = Instance.new("Folder", player)
statsFolder.Name = "Stats"
local levelVal = Instance.new("IntValue")
levelVal.Parent = statsFolder
levelVal.Name = "Level"
levelVal.Value = 1
local expVal = Instance.new("IntValue")
expVal.Parent = statsFolder
expVal.Name = "Experience"
local statPoints = Instance.new("IntValue")
statPoints.Parent = statsFolder
statPoints.Name = "StatPoints"
local defense = Instance.new("IntValue")
defense.Parent = statsFolder
defense.Name = "DefensePoints"
local damage = Instance.new("IntValue")
damage.Parent = statsFolder
damage.Name = "DamagePoints"
pcall(function()
local data = savedLevelsDS:GetAsync(player.UserId .. "LevelsDSS")
if data then
levelVal.Value = data[1]
expVal.Value = data[2]
statPoints.Value = data[3]
defense.Value = data[4]
damage.Value = data[5]
end
end)
expVal:GetPropertyChangedSignal("Value"):Connect(function()
local neededExp = math.floor(levelVal.Value ^ 1.5 + 0.5) * 500
if expVal.Value >= neededExp then
levelVal.Value += 1
statPoints.Value += 5
end
end)
end)
Event.OnServerEvent:Connect(function(player)
saveData(player)
end)
game.Players.PlayerRemoving:Connect(function(player)
saveData(player)
end)
game:BindToClose(function()
for _, player in game.Players:GetPlayers() do
saveData(player)
end
end)