So I have made a datasave for bool values. But there is this one value that works but does not. So I try to access it in another script and it does not work, and I have been told that the other script that I made was fine, so it is creating it which is the problem. I would like a couple of extra eyes on this. Thanks!
The problem in question is the exicutioneraxe[5] btw
local DataStoreService = game:GetService("DataStoreService")
local ds = DataStoreService:GetDataStore("datatest")
game.Players.PlayerAdded:Connect(function(plr)
local axes = Instance.new("Folder",plr)
axes.Name = "axes"
local Homemadeaxe = Instance.new("BoolValue",axes)
Homemadeaxe.Name = "Homemadeaxe"
Homemadeaxe.Value = true
local Normalaxe = Instance.new("BoolValue",axes)
Normalaxe.Name = "Normalaxe"
local Lumerjackaxe = Instance.new("BoolValue",axes)
Lumerjackaxe.Name = "Lumerjackaxe"
local Diamondaxe = Instance.new("BoolValue",axes)
Diamondaxe.Name = "Diamondaxe"
local Executioneraxe = Instance.new("BoolValue",axes)
Executioneraxe.Name = "Executioneraxe"
local Steampunkaxe = Instance.new("BoolValue",axes)
Steampunkaxe.Name = "Steampunkaxe"
local Voidaxe = Instance.new("BoolValue",axes)
Voidaxe.Name = "Voidaxe"
local Doubleaxe = Instance.new("BoolValue",axes)
Doubleaxe.Name = "Doubleaxe"
local success, dataofuser = pcall(ds.GetAsync, ds, plr.UserId)
if not success then
plr:Kick("Failed to load data. Please rejoin!")
end
if dataofuser ~= nil then
print("Found data for " .. plr.Name)
Homemadeaxe.Value = dataofuser[1]
Normalaxe.Value = dataofuser[2]
Diamondaxe.Value = dataofuser[3]
Lumerjackaxe.Value = dataofuser[4]
Executioneraxe.Value = dataofuser[5]
Doubleaxe.Value = dataofuser[6]
Steampunkaxe.Value = dataofuser[7]
Voidaxe.Value = dataofuser[8]
else
print("Replacing no data with new data.")
Homemadeaxe = true
Normalaxe = false
Diamondaxe = false
Lumerjackaxe = false
Executioneraxe = false
Doubleaxe = false
Steampunkaxe = false
Voidaxe = false
end
end)
local function save(player:Player)
local saveData = {
[1] = player.axes.Homemadeaxe.Value,
[2] = player.axes.Normalaxe.Value,
[3] = player.axes.Diamondaxe.Value,
[4] = player.axes.Lumerjackaxe.Value,
[5] = player.axes.Executioneraxe.Value,
[6] = player.axes.Doubleaxe.Value,
[7] = player.axes.Steampunkaxe.Value,
[8] = player.axes.Voidaxe.Value
}
local attempt = 0
local success
local result
repeat
success, result = pcall(ds.UpdateAsync, ds, player.UserId, function(old) return saveData end)
attempt += 1
until
success or attempt == 3
if not success then
warn(result)
end
end
local runService = game:GetService("RunService")
local players = game:GetService("Players")
game:BindToClose(function()
if runService:IsStudio() or #players:GetPlayers() <= 1 then task.wait(3) return nil end
for _, player in next, players:GetPlayers(), nil do
save(player)
end
task.wait(3)
end)
game:GetService("Players").PlayerRemoving:Connect(save)
Here is the other script which I was told it was fine if that helps where I access it.
local rp = game:GetService("ReplicatedStorage")
local plr = game:GetService("Players")
local re = game.ReplicatedStorage.OnJoin.Normalaxe
local rr = game.ReplicatedStorage.OnJoin.Diamondaxe
local rt = game.ReplicatedStorage.OnJoin.Lumberjackaxe
local ry = game.ReplicatedStorage.OnJoin.Executioneraxe
local ru = game.ReplicatedStorage.OnJoin.Doubleaxe
local ri = game.ReplicatedStorage.OnJoin.Steampunkaxe
local ro = game.ReplicatedStorage.OnJoin.Voidaxe
plr.PlayerAdded:Connect(function(player: Player)
local axes = player:WaitForChild("axes") -- I'm assuming this is some folder in player
if not axes then player:Kick("Data could not load, please rejoin.") end
local normalAxe = axes:WaitForChild("Normalaxe")
local diamondAxe = axes:WaitForChild("Diamondaxe")
local lumberjackAxe = axes:WaitForChild("Lumerjackaxe")
local ExecutionerAxe = axes:WaitForChild("Executioneraxe")
local DoubleAxe = axes:FindFirstChild("Doubleaxe")
local SteampunkAxe = axes:FindFirstChild("Steampunkaxe")
local VoidAxe = axes:FindFirstChild("Voidaxe")
print("a")
if not normalAxe then return end
if not diamondAxe then return end
if not lumberjackAxe then return end
if not ExecutionerAxe then return end
if not DoubleAxe then return end
if not SteampunkAxe then return end
if not VoidAxe then return end
wait(0.01)
if normalAxe.Value == true then
re:FireClient(player)
print("aa")
end
if diamondAxe.Value == true then
rr:FireClient(player)
print("100")
end
if lumberjackAxe.Value == true then
rt:FireClient(player)
end
if ExecutionerAxe.Value == true then
ry:FireClient(player)
end
if DoubleAxe.Value == true then
ru:FireClient(player)
end
if SteampunkAxe.Value == true then
ri:FireClient(player)
end
if VoidAxe.Value == true then
ro:FireClient(player)
end
end)