Hello,
Im trying to save the players - bought tools. Doing so im using the normal data stores, yes im aware of profile service etc etc.
Saving the tools work, sort off. What doesnt work is that it prints out the selected tool, but when printing that tool on another script, it prints out the default tool.
Saving function:
local function save(plr:Player)
local data = manager.getTools(plr)
if data == nil then return end
data.SelectedTool = tostring(data.SelectedTool)
local succes, err = pcall(function()
datastore:SetAsync(prefix..plr.UserId, data)
end)
if succes then
print("Succesfully saved tools for: " .. plr.Name)
print("savedTools: ")
print(data)
else
warn(err)
end
end
The data prints out as the following:
Loading function:
local function load(plr:Player)
if not manager.getTools(plr) then
manager.setUp(plr)
end
local data = nil
local success, err = pcall(function()
data = datastore:GetAsync(prefix..plr.UserId)
end)
if data == nil then
print("Success, plr has no tool data")
manager.setUp(plr)
elseif success and data then
manager.setUp(plr)
for i, tool in data.Tools do
manager.GiveTools(plr, tool)
end
manager.SelectTool(plr, tools:FindFirstChild(data.SelectedTool))
print("Succes loading data for: " .. plr.Name)
print("data: ")
print(data)
elseif not success then
warn(err)
end
end
What im trying to achieve is that the player their tools will get saved, and later the tools can be loaded. Im using a module script to keep track of the player their items.
Does anyone know why the selectedTool does infact not change even tho is set it to the new tool?
manager.SelectTool(plr, tools:FindFirstChild(data.SelectedTool))