why are my tools not appearing in my inventory? it literally prints “creating tool”
dw about the datastore and module
please help ive been trying to fix this for the last 5 days
for i,v in ipairs(data['ItemTable']) do
local foods = game.ReplicatedStorage.food
local tools = foods.tools
print(v .. ' is in itemtable.')
for i, tool in pairs(tools:GetChildren()) do
if tool.Name == v then
print('creating tool')
local newtool = tool:Clone()
newtool.Name = v
newtool.Handle.Anchored = false
newtool.Parent = plr.Backpack
module.ItemUse(newtool.Handle:FindFirstChild("LuckBooster").Value, newtool, newtool.Handle:FindFirstChild('Time').Value, plr, v)
else
print('nope')
end
end
end
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local DataStoreService = game:GetService("DataStoreService")
local rollstore = DataStoreService:GetDataStore("rollstore")
local module = require(script.Parent.Parent.Spawn.SeparateScript)
local function load(plr:Player)
local folder = Instance.new("Folder", plr)
folder.Name = 'leaderstats'
local rolls = Instance.new("IntValue", folder)
rolls.Name = 'Rolls'
rolls.Value = 0
local luckmultiplier = Instance.new("IntValue", folder)
luckmultiplier.Name = 'Luck'
luckmultiplier.Value = 1
luckmultiplier.Changed:Connect(function(newvalue)
luckmultiplier.Value = newvalue
print(newvalue)
end)
local playerid = "Player_" .. plr.UserId
local data
local success, err = pcall(function()
data = rollstore:GetAsync(playerid)
end)
if data then
if data['Rolls'] then
rolls.Value = data['Rolls']
else
rolls.Value = 0
end
else
rolls.Value = 0
end
if data['ItemTable'] then
print('ItemTable is not nil')
for i,v in ipairs(data['ItemTable']) do
local foods = game.ReplicatedStorage.food
local tools = foods.tools
print(v .. ' is in itemtable.')
for i, tool in pairs(tools:GetChildren()) do
if tool.Name == v then
print('creating tool')
local newtool = tool:Clone()
newtool.Name = v
newtool.Handle.Anchored = false
newtool.Parent = plr.Backpack
module.ItemUse(newtool.Handle:FindFirstChild("LuckBooster").Value, newtool, newtool.Handle:FindFirstChild('Time').Value, plr, v)
else
print('nope')
end
end
end
else
print('its nil rn')
end
end
local function save(plr:Player)
local items = {}
local backpack = plr.Backpack
for i, item in backpack:GetChildren() do
table.insert(items, item.Name)
print(item.Name)
end
for i, itemers in ipairs(items) do
print(itemers)
end
local datatobesaved = {
Rolls = plr.leaderstats.Rolls.Value,
ItemTable = items
}
local playerid = "Player_" .. plr.UserId
local success, err = pcall(function()
rollstore:UpdateAsync(playerid, function(old)
for i, v in pairs(datatobesaved) do
if i == nil or v == nil then
datatobesaved = old
print('datasave = old')
end
end
--you can add individual checks to make sure each data element
--is there and ready to be saved.
return datatobesaved
end)
end)
if success then
print("data saved!")
else
print("data failed to save!")
end
end
local function onGameClose()
if runService:IsStudio() then task.wait(3) return nil end
for _, player in ipairs(players:GetPlayers()) do
save(player)
end
task.wait(3)
end
players.PlayerAdded:Connect(load)
players.PlayerRemoving:Connect(save)
game:BindToClose(onGameClose)
If the value of this changes why do you then manually change it? The reason this event has been fired is because the value has changed so their is no need to set it to it’s own value
I’ve had that problem before, try it on the server, if it works on the server then it seems like it ONLY works on the server and not client, I’ll try help you then
i am guessing it is bcz the plr left so “plr.Character” is nil
if i am right how could i make plr.character still usable
local function save(plr)
local items = {}
local essence = plr.Character:FindFirstChild("Head").essence -- line 82
local function RGBstringToColor3(RGBstring)
return tostring(RGBstring:ToHex())
end
local essencecolor = RGBstringToColor3(essence.BillBoardGui.Essence.TextColor3)
local essencesave = {
EssenceName = essence.BillBoardGui.Essence.Text,
EssenceColor = essencecolor,
EssenceFont = essence.BillBoardGui.Essence.Font.Name,
Chance = essence.chance.BillBoardGui.Chance.Text,
}
local backpack = plr.Backpack
for i, item in backpack:GetChildren() do
table.insert(items, item.Name)
print(item.Name)
end
for i, itemers in ipairs(items) do
print(itemers)
end
local datatobesaved = {
Rolls = plr.leaderstats.Rolls.Value,
ItemTable = items,
CurrentEssence = essencesave,
}
local playerid = "Player_" .. plr.UserId
local success, err = pcall(function()
rollstore:UpdateAsync(playerid, function(old)
for i, v in pairs(datatobesaved) do
if i == nil or v == nil then
datatobesaved = old
print('datasave = old')
end
end
--you can add individual checks to make sure each data element
--is there and ready to be saved.
return datatobesaved
end)
end)
if success then
print("data saved! (server)")
else
print("data failed to save!")
end
end
hey dude, i am still confused by out of the blue my code starting working with no real modifications?
so my problem solved, but immense thank you for your help!