You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? why isnt it working
What is the issue? I cant figure it out, its been about 4 hours and im about to lose my mind, it keeps saying: ServerScriptService.Player data:90: attempt to index nil with ‘FrenchFry3’
I have tried everything, even rewriting the script. MAYBE it could have something to do with my Module script?
Here is my Script:
local success, returnValue
repeat
waitForRequestBudget(Enum.DataStoreRequestType.GetAsync)
success, returnValue = pcall(dataStore.GetAsync, dataStore, key)
until success or not Players:FindFirstChild(player.Name)
if success then
if returnValue == nil then
returnValue = {
Food = 0,
Coins = 0,
}
end
player.leaderstats.Food.Value = if returnValue.Food ~= nil then returnValue.Food else 0
player.leaderstats.Coins.Value= if returnValue.Coins ~= nil then returnValue.Coins else 0
player.inventory.EquippedTool.Value = if returnValue.Inventory.EquippeedTool ~= nil then returnValue.Inventory.EquippeedTool else "FrenchFry"
for _, tool in ipairs(player.inventory.OwnedTools:GetChildren()) do
tool.Value = (returnValue.Inventory.OwnedTools[tool.Name] or false)
end
else
player:Kick("There was an error loading your Data! Roblox's DataStore might be down, try again later!")
print(player.Name.."Data loading ERROR!!!")
end
Im still new to scripting so i have no clue but i read something about index nil where it says index nil means that the script cannot find the object. This often is because the path to the object is wrong.
You are not providing enough information, please provide this module fully. As well as where you require this module.
We would need to know what returnValue.
Also please can you describe what you are doing instead of just giving us a script and trying to get us to understand, “why isnt it working” is not a good achievement.
Based on the provided snippet, returnValue is missing necessary keys.
In one scenario, if returnValue is not fetched from the DataStore, then it defaults to a dictionary that is missing an Inventory array, which will cause an error when attempting to access returnValue.Inventory.OwnedTools. This doesn’t seem to be the error occurring here though.
Presumably, returnValue.Inventory exists, but returnValue.Inventory.OwnedTools does not. I can’t say for certain where you should be adding the OwnedTools table, but it does need to be added somewhere. If you don’t want to do this, then you can rewrite line 90 to handle a nil table value:
tool.Value = if (returnValue.Inventory and returnValue.Invevntory.OwnedTools and returnValue.Inventory.OwnedTools[tool.Name]) then returnValue.Inventory.OwnedTools[tool.Name] else false
Slightly messy ternary operator, but it gets the job done.
I made this in the heat of the moment but may you tell me what information you need? But I’m trying to go through all the owned tools that I added to the players inv such as French fry, French fry2,French fry3. and its not giving the tools to them. before I added the “tool.Value = (returnValue.Inventory.OwnedTools[tool.Name] or false)” line of code it was working but now its not.
I told you exactly what we need, could you read a bit more carefully please, we need the full script which contains line 90 as well. That way we can easily help you and find out the issue without having to ask you for more.