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)
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.
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)
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
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.
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?
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.