#gng when i check inventory theres only a rappier no wand pls help

1 messages · Page 1 of 1 (latest)

graceful sandal
#

gng when i check inventory theres only a rappier no wand pls help

#

BRU

formal vector
#

ok

#

yo chill

#
local DataStoreService = game:GetService("DataStoreService")
local RS = game:GetService("ReplicatedStorage")
local dataStoreExpEvent = RS.Events:FindFirstChild("DatastoreEXP")
local dataStoreMoneyEvent = RS.Events:FindFirstChild("DatastoreMoney")
local lvlStore = DataStoreService:GetDataStore("LVL")
local EXPStore = DataStoreService:GetDataStore("EXP")
local waveLootEvent = RS.Events:FindFirstChild("WaveLootReady")
local grantLootRE = RS.Events:FindFirstChild("GrantLoot")
local RarityMod = require(RS.Modules:FindFirstChild("RandomRarityEtc"))
local inventoryMod = require(RS.Modules:WaitForChild("PhysicalInventoryModule"))
local inventoryDataEvent = RS.Events:WaitForChild("SendInventoryData")
local inventoryDataStore = DataStoreService:GetDataStore("Inventory")
local moneyDataStore = DataStoreService:GetDataStore("Money")
graceful sandal
#

TYY

formal vector
#

no

graceful sandal
#

soo

formal vector
#

im making it easier to read for myself

graceful sandal
#

oh ok

#
            
        else
            for i = 1, 1 do
                local Rapier = RS.Items:FindFirstChild("Rapier"):Clone()

                Rapier.Parent = player:FindFirstChild("InventoryFolder")
                Rapier:SetAttribute("Rarity", RarityMod.GetRandomRarities())
                Rapier.Name = "Rapier_" .. math.random()
                inventoryMod.AddToPhysicalInventory(player, Rapier)

                local Wand = RS.Items:FindFirstChild("Wand"):Clone()

                Wand.Parent = player:FindFirstChild("InventoryFolder")
                Wand:SetAttribute("Rarity", RarityMod.GetRandomRarities())
                Wand.Name = "Wand" .. math.random()
                inventoryMod.AddToPhysicalInventory(player, Wand)
            end
        end
        
        UpdateInventory(player)
        
        dataStoreExpEvent:Fire(player, exp, lvl, 0)
        dataStoreMoneyEvent:Fire(player, money, 0)
        playerStats.Parent = player
        lvl.Parent = playerStats
        exp.Parent = playerStats
        money.Parent = playerStats
        
    else
        print("Something went wrong while loading your data")
    end
    
    
    UpdateInventory(player)
    ```
#

thes2e are the main linez

formal vector
graceful sandal
#

lol

cosmic hollow
graceful sandal
#

lol

cosmic hollow
#

i think i see the problem

graceful sandal
#

?

formal vector
#

coding conventions be damned fr

graceful sandal
#

1,2?

cosmic hollow
#

😭

graceful sandal
#

lol

cosmic hollow
#

i dont think ur adding the wand to their inventory bro

#

just the rapier

#

hold on let me actually look rq

formal vector
#

i would say use debugger to step thru addtophysicalinventory but if you dk how and dont wanna learn this works too

#

most ppl dk how

cosmic hollow
#

yeah

#

add prints between each line

#

see where it stops

formal vector
#

is inv empty?

graceful sandal
#

wat should print say

graceful sandal
#

rapier in there

#

when

#

u play

graceful sandal
formal vector
graceful sandal
#

kk

formal vector
#

like when you do getasync

graceful sandal
#

19:48:34.285 tempolate - Server - PhysicalInventoryModule:80
19:48:36.303 Infinite yield possible on 'cloud_9599081549.Moon VFX Exporter.Moon VFX Exporter.ExporterFramesHandler:WaitForChild("Reference")' - Studio
19:48:36.303 Stack Begin - Studio
19:48:36.303 Script 'cloud_9599081549.Moon VFX Exporter.Moon VFX Exporter.ExporterFramesHandler', Line 3 - Studio
19:48:36.303 Stack End - Studio
19:48:37.101 Infinite yield possible on 'Players.NexusBloxz:WaitForChild("isAttacking")' - Studio
19:48:37.101 Stack Begin - Studio
19:48:37.101 Script 'Players.NexusBloxz.PlayerGui.Abilities.Frame.Ability1.Cooldown.Cooldown', Line 4 - Studio - Cooldown:4
19:48:37.101 Stack End - Studio
19:48:37.101 Infinite yield possible on 'Players.NexusBloxz:WaitForChild("isAttacking")' - Studio
19:48:37.101 Stack Begin - Studio
19:48:37.101 Script 'Players.NexusBloxz.PlayerGui.Abilities.Frame.ClassAbility.Cooldown.Cooldown', Line 4 - Studio - Cooldown:4
19:48:37.101 Stack End - Studio
19:48:37.101 Infinite yield possible on 'Players.NexusBloxz:WaitForChild("isAttacking")' - Studio
19:48:37.101 Stack Begin - Studio
19:48:37.101 Script 'Players.NexusBloxz.PlayerGui.Abilities.Frame.Ability3.Cooldown.Cooldown', Line 4 - Studio - Cooldown:4
19:48:37.101 Stack End - Studio
19:48:37.329 Infinite yield possible on 'cloud_9599081549.Moon VFX Exporter.Moon VFX Exporter.ExporterFramesHandler:WaitForChild("Reference")' - Studio
19:48:37.329 Stack Begin - Studio
19:48:37.329 Script 'cloud_9599081549.Moon VFX Exporter.Moon VFX Exporter.ExporterFramesHandler', Line 3 - Studio
19:48:37.329 Stack End - Studio

#

@formal vector

#

theres no hi

formal vector
#

lol

#

@cosmic hollow

cosmic hollow
#

yo

cosmic hollow
graceful sandal
#

        else
            for i = 1, 1 do
                local Rapier = RS.Items:FindFirstChild("Rapier"):Clone()

                Rapier.Parent = player:FindFirstChild("InventoryFolder")
                Rapier:SetAttribute("Rarity", RarityMod.GetRandomRarities())
                Rapier.Name = "Rapier_" .. math.random()
                inventoryMod.AddToPhysicalInventory(player, Rapier)
                
                print("hi")
                local Wand = RS.Items:FindFirstChild("Wand"):Clone()

                Wand.Parent = player:FindFirstChild("InventoryFolder")
                Wand:SetAttribute("Rarity", RarityMod.GetRandomRarities())
                Wand.Name = "Wand" .. math.random()
                inventoryMod.AddToPhysicalInventory(player, Wand)
            end
        end
        
        UpdateInventory(player)
        
        dataStoreExpEvent:Fire(player, exp, lvl, 0)
        dataStoreMoneyEvent:Fire(player, money, 0)
        playerStats.Parent = player
        lvl.Parent = playerStats
        exp.Parent = playerStats
        money.Parent = playerStats
        
    else
        print("Something went wrong while loading your data")
    end
    
    
    UpdateInventory(player)
    ```
formal vector
#

show us the function you're calling in

local inventoryMod = require(RS.Modules:WaitForChild("PhysicalInventoryModule"))
cosmic hollow
#

print(typeof(inv), #inv) add this line after line 110 and lmk if it prints anything

graceful sandal
#
local DataStoreService = game:GetService("DataStoreService")
local DS = DataStoreService:GetDataStore("PlayerInventory")
local module = {}
local Inventory = {}
local maxSlots = 50


local function getKey(userId)
    
    return "Inventory_" .. userId
    
end

function module.LoadInventory(userId)
    
    local key = getKey(userId)
    local success, data = pcall(function()-- data is the returned value
        return DS:GetAsync(key)
    end)
    if success and type(data) == "table" then
        Inventory[userId] = data
    else
        
        Inventory[userId] = {}
        
    end
    for i = 1, maxSlots do
        Inventory[userId][i] = Inventory[userId][i]
    end
end

function module.SaveInventory(userId)
    
    local key = getKey(userId)
    local data = Inventory[userId] or {}
    pcall(function()
        DS:SetAsync(key, data)
    end)
    
end



function module.CreateInventory(userId)
    
    if not Inventory[userId] then
        module.LoadInventory(userId)
    end
    
end
function module.GetInventory(userId)
    
    module.CreateInventory(userId)
    return Inventory[userId]
    
end
function module.AddToInventory(userId, itemName)
    module.CreateInventory(userId)
    local inv = Inventory[userId]
    for i = 1, maxSlots do
        if not inv[i] then
            inv[i] = itemName
            return true
        end
    end
    return false
end
function module.RemoveFromInventory(userId, slotIndex)
    module.CreateInventory(userId)
    if Inventory[userId][slotIndex] then
        Inventory[userId][slotIndex] = nil
        return true
    end
    return false
end
return module``` @formal vector
#
  19:53:36.698  Infinite yield possible on 'cloud_9599081549.Moon VFX Exporter.Moon VFX Exporter.ExporterFramesHandler:WaitForChild("Reference")'  -  Studio
  19:53:36.698  Stack Begin  -  Studio
  19:53:36.698  Script 'cloud_9599081549.Moon VFX Exporter.Moon VFX Exporter.ExporterFramesHandler', Line 3  -  Studio
  19:53:36.698  Stack End  -  Studio
  19:53:37.695  Infinite yield possible on 'cloud_9599081549.Moon VFX Exporter.Moon VFX Exporter.ExporterFramesHandler:WaitForChild("Reference")'  -  Studio
  19:53:37.695  Stack Begin  -  Studio
  19:53:37.695  Script 'cloud_9599081549.Moon VFX Exporter.Moon VFX Exporter.ExporterFramesHandler', Line 3  -  Studio
  19:53:37.695  Stack End  -  Studio
  19:53:38.277  Infinite yield possible on 'Players.NexusBloxz:WaitForChild("isAttacking")'  -  Studio
  19:53:38.277  Stack Begin  -  Studio
  19:53:38.277  Script 'Players.NexusBloxz.PlayerGui.Abilities.Frame.Ability1.Cooldown.Cooldown', Line 4  -  Studio - Cooldown:4
  19:53:38.277  Stack End  -  Studio
  19:53:38.277  Infinite yield possible on 'Players.NexusBloxz:WaitForChild("isAttacking")'  -  Studio
  19:53:38.277  Stack Begin  -  Studio
  19:53:38.277  Script 'Players.NexusBloxz.PlayerGui.Abilities.Frame.ClassAbility.Cooldown.Cooldown', Line 4  -  Studio - Cooldown:4
  19:53:38.278  Stack End  -  Studio
  19:53:38.278  Infinite yield possible on 'Players.NexusBloxz:WaitForChild("isAttacking")'  -  Studio
  19:53:38.278  Stack Begin  -  Studio
  19:53:38.278  Script 'Players.NexusBloxz.PlayerGui.Abilities.Frame.Ability3.Cooldown.Cooldown', Line 4  -  Studio - Cooldown:4
  19:53:38.278  Stack End  -  Studio``` @cosmic hollow
formal vector
cosmic hollow
#

disable warnings from output

graceful sandal
#
19:56:31.976  table 1  -  Server - leaderstats:111
  19:56:31.977  tempolate  -  Server - PhysicalInventoryModule:80
  19:56:34.812  Stack Begin  -  Studio
  19:56:34.812  Script 'cloud_9599081549.Moon VFX Exporter.Moon VFX Exporter.ExporterFramesHandler', Line 3  -  Studio
  19:56:34.812  Stack End  -  Studio
  19:56:34.813  Stack Begin  -  Studio
  19:56:34.813  Script 'cloud_9599081549.Moon VFX Exporter.Moon VFX Exporter.ExporterFramesHandler', Line 3  -  Studio
  19:56:34.813  Stack End  -  Studio
  19:56:35.759  Stack Begin  -  Studio
  19:56:35.759  Script 'Players.NexusBloxz.PlayerGui.Abilities.Frame.Ability1.Cooldown.Cooldown', Line 4  -  Studio - Cooldown:4
  19:56:35.759  Stack End  -  Studio
  19:56:35.759  Stack Begin  -  Studio
  19:56:35.759  Script 'Players.NexusBloxz.PlayerGui.Abilities.Frame.ClassAbility.Cooldown.Cooldown', Line 4  -  Studio - Cooldown:4
  19:56:35.759  Stack End  -  Studio
  19:56:35.760  Stack Begin  -  Studio
  19:56:35.760  Script 'Players.NexusBloxz.PlayerGui.Abilities.Frame.Ability3.Cooldown.Cooldown', Line 4  -  Studio - Cooldown:4
  19:56:35.760  Stack End  -  Studio```
#

@cosmic hollow

cosmic hollow
#

whats the inventorymod script look like

formal vector
#

also is the datastore working

#

bc if it is then you are just gonna load the same thing over bc of your else statement

cosmic hollow
formal vector
graceful sandal
#
local DataStoreService = game:GetService("DataStoreService")
local DS = DataStoreService:GetDataStore("PlayerInventory")
local module = {}
local Inventory = {}
local maxSlots = 50


local function getKey(userId)
    
    return "Inventory_" .. userId
    
end

function module.LoadInventory(userId)
    
    local key = getKey(userId)
    local success, data = pcall(function()-- data is the returned value
        return DS:GetAsync(key)
    end)
    if success and type(data) == "table" then
        Inventory[userId] = data
    else
        
        Inventory[userId] = {}
        
    end
    for i = 1, maxSlots do
        Inventory[userId][i] = Inventory[userId][i]
    end
end

function module.SaveInventory(userId)
    
    local key = getKey(userId)
    local data = Inventory[userId] or {}
    pcall(function()
        DS:SetAsync(key, data)
    end)
    
end



function module.CreateInventory(userId)
    
    if not Inventory[userId] then
        module.LoadInventory(userId)
    end
    
end
function module.GetInventory(userId)
    
    module.CreateInventory(userId)
    return Inventory[userId]
    
end
function module.AddToInventory(userId, itemName)
    module.CreateInventory(userId)
    local inv = Inventory[userId]
    for i = 1, maxSlots do
        if not inv[i] then
            inv[i] = itemName
            return true
        end
    end
    return false
end
function module.RemoveFromInventory(userId, slotIndex)
    module.CreateInventory(userId)
    if Inventory[userId][slotIndex] then
        Inventory[userId][slotIndex] = nil
        return true
    end
    return false
end
return module``` @cosmic hollow
graceful sandal
formal vector
#

so you're loading the same inventory over and over again then?

graceful sandal
graceful sandal
#

how can i fix

formal vector
#

try renaming the datastore to something different or renaming the keys rq

cosmic hollow
#
``` add this after the if and else statement
#

i wanna see what the inventory looks like

formal vector
#

I think its running this top part every time

graceful sandal
cosmic hollow
cosmic hollow
formal vector
#

yeah and i think thats why bc its in the else part

graceful sandal
graceful sandal
cosmic hollow
formal vector
graceful sandal
# cosmic hollow open the table in output

    if success and worked and yes and ofcourse then
        exp.Value = returned or 1
        lvl.Value = ret or 1
        money.Value = moneyRet or 0

        -- NEW HEALTH LOGIC START --
        local function updateMaxHealth(character)
            local humanoid = character:WaitForChild("Humanoid")
            -- Formula: Base 100 + (25 * Level)
            local newMax = 100 + (lvl.Value * 25)

            humanoid.MaxHealth = newMax
            humanoid.Health = newMax -- Heals them to full on level up/spawn
        end
        print(typeof(inv), #inv)
vocal frostBOT
#

studio** You are now Level 6! **studio

cosmic hollow
#

when u see that in ur output

#

if u click on the ">"

#

it opens it

graceful sandal
cosmic hollow
#

send me what it shows

graceful sandal
#

ohhh

#

isee

graceful sandal
#

@cosmic hollow

cosmic hollow
#

okay thats not it

#

uhm

#

do you see any lines printing from the script its in

graceful sandal
#

btqw

#

error

#

20:04:46.784 ServerScriptService.InGame.leaderstats:152: attempt to call a nil value - Server - leaderstats:152

graceful sandal
#

bru

#

@cosmic hollow @formal vector

formal vector
#

put a print here and test

graceful sandal
formal vector
#

yeah so thats kind of what i thought you see the problem?

graceful sandal
#

soo

#

how can i change

formal vector
#

right now you're only giving the wand if the player has nothing saved, but you already have the inventory with the rapier saved

graceful sandal
#

yes

formal vector
#

Change "Inventory" to some other name like "Inventory1" or something. This is making a fresh datastore.

graceful sandal
#

local inventory1 = DataStoreService:GetDataStore("Inventory")

#

@formal vector

formal vector
#

no

#

the pink part

#

that is the name of the datastore you want

graceful sandal
#

ohhh

#

Done

formal vector
#

did you test

graceful sandal
#

nothings

#

there

#

no rapier

#

or wand

#

@formal vector

formal vector
#

is there anything in output

graceful sandal
formal vector
#

its bc you did #inv and inv doesnt exist

graceful sandal
#

ohh

#

i fixed

#

its inventorydatastre

#

notinv

formal vector
#

no like inv is the inventory of the player retrieved from the datastore but on first playthrough there's nothing to retrieve

#

so it is setting inv to nil and you are checking nil

graceful sandal
#

ill sho

formal vector
#

bruh what

graceful sandal
#

change

#

#inv

#

to

#

inventorydatastore

formal vector
#

but inventorydatastore is like a collection of everybody's inventorys

graceful sandal
#

ya

formal vector
#

im so confused by your code

graceful sandal
#

samwe

formal vector
#

why does loadinventory take both userid and inv when in the code you sent later loadinventory is defined as only taking userid

#

its not even userid you're just giving the player

#

but like assuming all that works what im saying is some other player can join with nothing and you're going to have an error

#

bc the only reason it worked is the datastore was empty and now its not so if anyone tries to join it'll try to load their data and there wont be any

#

any new player*

graceful sandal
#

idkk

formal vector
#

to prove it you could start a 2 person server on studio, but I'm saying you should just change all of those conditions into one if inv then

graceful sandal
#

kk

#

btw

#

@formal vector

#

wanna help me work on the game

formal vector
#

no im actually supposed to be studying rn and this is frustrating and imma switch to unity soon anyways

iron cradle
#

bro doesnt even know what he cooked up 💯

hardy wedge
#

wat