- What do you want to achieve? Keep it simple and clear!
I want to successfully save and load player tools. Specifically, I need my code to ensure that when a player acquires a tool the tool saves to the database.
- What is the issue? Include screenshots / videos if possible!
I am encountering an issue with saving player tools in Roblox Studio. During gameplay, a Boolean value associated to a tool is set to true. Consequently, when the player re-enters the game, the tool that should appear in their inventory based on this Boolean value does not load. though, I dont suspect there might be an error in my code related to the saving and loading process because it already works with currency. I suspect it being something with the syntax.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried searching for general solutions related to saving and loading, but my problem seems too specific to find relevant answers.
Here is the loaddata
function where I believe the problem lies:
function loaddata(plr)
local userid = plr.UserId
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local boolvalues = Instance.new("Folder")
boolvalues.Name = "boolvalues"
boolvalues.Parent = plr
local doubloons = Instance.new("IntValue")
doubloons.Name = "Doubloons"
doubloons.Parent = leaderstats
local tooltable = {}
for _, v in pairs(toolfolder:GetChildren()) do
local value = Instance.new("BoolValue")
value.Name = "owns" .. v.Name
value.Parent = boolvalues
tooltable[value.Name] = false
end
local success
local playerdata
local attempt = 1
repeat
success, playerdata = pcall(function()
return db:GetAsync(userid, playerdata)
end)
attempt += 1
if not success then
task.wait(2)
end
until success or attempt == 5
if success then
print("loaded players data")
if not playerdata then
print("assigning default data")
playerdata = {
["Doubloons"] = 0,
Inventory = tooltable
}
end
currentdata[userid] = playerdata
else
plr:Kick("Unable to assign data")
end
doubloons.Value = currentdata[userid].Doubloons
-- I suspect it being wrong somewhere in here
for _, v in pairs(boolvalues:GetChildren()) do
print(v.Value)
print(currentdata[userid].Inventory[v.Name])
v.Value = currentdata[userid].Inventory[v.Name]
v.Changed:Connect(function()
currentdata[userid][v.Name] = v.Value
print(currentdata[userid][v.Name])
end)
end
doubloons.Changed:Connect(function()
currentdata[userid].Doubloons = doubloons.Value
end)
leaderstats.Parent = plr
loadtools(plr)
end