Inventory system failed to work, help

I am trying to make a system so that it detects how much is the value of each cup and duplicating a template frame with the name of the cup and repeat it to how many times in the cup value

local templatec = script:WaitForChild("TemplateCups")
local templatet = script:WaitForChild("TemplateTrollge")
local cupsframe = script.Parent.CupsFrame
local trollgeframe = script.Parent.TrollgeFrame
local player = game.Players.LocalPlayer




for i, v in pairs(player.Cups:GetChildren()) do
	if v.Name == "Oil" then
		for i = 1, v.Value, 1 do
			print(v)
			local clone = templatec:Clone()
			clone.Parent = cupsframe.ScrollingFrame
			clone.Name = v.Name
			clone.TextLabel.Text = v.Name
		end
	elseif v.Name == "Blood" then
		for i = 1, v.Value, 1 do
			print(v)
			local clone = templatec:Clone()
			clone.Parent = cupsframe.ScrollingFrame
			clone.Name = v.Name
			clone.TextLabel.Text = v.Name
		end
 	end
end

The script is not printing anything (no errors no prints nothing)

2 Likes

Is the player.Cups a Folder or ConfigFolder inside the Player or is it some sort of value? Then also, are the Cups:GetChildren() some sort of Number/IntValue?

The other thing I can think of is the for i, v loop is not in a function or while task.wait() loop which means the code could be running before anything is in the player’s inventory, but when something gets added, the code has already ran so it doesn’t loop through everything.

3 Likes

Folder, Int value i tried putting it in a while loop and it just spammed the ui

3 Likes

If it needs to update whenever something gets added then something with .ChildAdded should possibly work.

local templatec = script:WaitForChild("TemplateCups")
local templatet = script:WaitForChild("TemplateTrollge")
local cupsframe = script.Parent.CupsFrame
local trollgeframe = script.Parent.TrollgeFrame
local player = game.Players.LocalPlayer

function addCup(newCup)
    for count = 1, newCup.Value, 1 do
        if newCup.Name == "Oil" and newCup:IsA("IntValue") then
            print(newCup)
            local clone = templatec:Clone()
            clone.Name = newCup.Name
            clone.TextLabel.Text = newCup.Name
            clone.Parent = cupsframe.ScrollingFrame
        elseif newCup.Name == "Blood" and newCup:IsA("IntValue") then
            print(newCup)
            local clone = templatec:Clone()
            clone.Name = newCup.Name
            clone.TextLabel.Text = newCup.Name
            clone.Parent = cupsframe.ScrollingFrame
        end
    end
end)

-- Will Run on Script Start incase There is Anything in the Folder
for _, cup in ipairs(player.Cups:GetChildren()) do
    addCup(cup)
end
-- Will Add a Cup Whenever a Cup is Added to the Folder
player.Cups.ChildAdded:Connect(addCup)
2 Likes

The script only adds it one time though, my value is over 1 so thats why i tried for i = 1 loop but didnt work

1 Like

That was my bad, I forgot about that part. I edited the script for the for loop back in it, just copy the code again.

1 Like

Now its not working at all wierdd no errors no prints

1 Like

Add a print(newCup.Value) right below the for count = 1 and make sure it’s getting the value

1 Like

yeah its not printing anything

1 Like

So it worked before when there was no for count loop, but when you add the loop it doesn’t work?

1 Like

Yes indeed, character limit yk

1 Like

Sorry I told you to put the print in the wrong spot lol oopsie. Put the print(newCup.Value) BEFORE not below the for count loop. I was thinking before and typed below. See if that prints a number.

print(newCup.Value)
for count = 1, newCup.Value, 1 do

wouldn’t that just print it once when the function gets called?

Yes but right now the loop isn’t working so that will show you what the IntValue is. If it errors or prints 0 then there is some sort of issue elsewhere. This is the best test because the for count loop needs the newCup.Value number, but there has to be something wrong with the number if the loop doesn’t work, but the code inside the loop works without the loop there.

Yeah it did print 0 when I play tested

That’s why the code isn’t working. Then my question is, do you change that number from 0 to say 3 or do you add a new IntValue inside the Cups folder?

Well my values are already set, blood = 23 and oil = 1

When you play test, is there something inside the cups folder that has an IntValue of 0 because if the values are set then there has to be something inside the folder that the loop grabs that has a value of 0.

nope just the 2 values blood and oil that are over 1

This will print the object then print the name and value of the object.

print(newCup)
print(newCup.Name.. " - ".. newCup.Value)
for count = 1, newCup.Value, 1 do