What do you want to achieve? Keep it simple and clear!
I want the value ALWAYS decrease 1 Instead of 2,3,4 etc.
What is the issue? Include screenshots / videos if possible!
When I use the function 1st time, everything works fine! Like the value decreases 1, and etc. But when I use it more than 1 times, the value starts to decrease more than 1, like 2nd use, the value decreases 2, 3rd use, the value decreases 3 etc.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Well, I Couldn’t find any topic like this neither in devforum neither in Developer Hub.
The script is;
local FoodDebounce = false
local function OpenItemStuff()
local Collected = 0
local Repeat = 0
local FoodFolder = Player:WaitForChild("Foods")
Dialogue.MainText.SurfaceGui.Text.Text = ""
local FoodInLighting = nil
local FoodList = {}
for i, v in pairs(FoodFolder:GetChildren()) do
if v.Value == 1 or v.Value > 1 then
Collected = Collected + v.Value
FoodInLighting = game.Lighting.Food:FindFirstChild(v.Name)
Repeat = v.Value
repeat
local success, fail = pcall(function()
table.insert(FoodList, FoodInLighting.Name)
end)
Repeat = Repeat -1
until Repeat == 0
print(#FoodList)
print(Collected)
Dialogue.MainText.SurfaceGui.Text.Text = ""
end
end
if not FoodDebounce then
FoodDebounce = true
if FoodList[1] then
Dialogue.Food1.SurfaceGui.Text.Text = game.Lighting.Food:FindFirstChild(FoodList[1]).FoodName.Value
Dialogue.Food1.ClickDetector2.MaxActivationDistance = 32
Dialogue.Food1.ClickDetector2.MouseClick:Connect(function()
local HealSound = game.Lighting.Assets.Battle.Heal:Clone()
HealSound.Parent = FightFolder
HealSound:Play()
CloseItemStuff()
MonsterCharacter.Main.Events.UseItem:Fire(tostring(FoodList[1]), Dialogue.MainText.SurfaceGui.Text)
game.Lighting.Food:FindFirstChild(FoodList[1]).Tool.Food.WhenHealed:Fire(Player)
FoodFolder:FindFirstChild(FoodList[1]).Value = FoodFolder:FindFirstChild(FoodList[1]).Value - 1
local success, fail = pcall(function()
table.remove(FoodList, table.find(FoodList, FoodInLighting.Name))
end)
wait(MonsterCharacter.Main.Values.TimeWaitForPass.Value + 1)
TakeAwayTurn()
return
end)
end
if FoodList[2] then
Dialogue.Food2.SurfaceGui.Text.Text = game.Lighting.Food:FindFirstChild(FoodList[2]).FoodName.Value
Dialogue.Food2.ClickDetector2.MaxActivationDistance = 32
Dialogue.Food2.ClickDetector2.MouseClick:Connect(function()
local HealSound = game.Lighting.Assets.Battle.Heal:Clone()
HealSound.Parent = FightFolder
HealSound:Play()
CloseItemStuff()
MonsterCharacter.Main.Events.UseItem:Fire(tostring(FoodList[2]), Dialogue.MainText.SurfaceGui.Text)
game.Lighting.Food:FindFirstChild(FoodList[2]).Tool.Food.WhenHealed:Fire(Player)
FoodFolder:FindFirstChild(FoodList[2]).Value = FoodFolder:FindFirstChild(FoodList[2]).Value - 1
local success, fail = pcall(function()
table.remove(FoodList, table.find(FoodList, FoodInLighting.Name))
end)
wait(MonsterCharacter.Main.Values.TimeWaitForPass.Value + 1)
TakeAwayTurn()
return
end)
end
if FoodList[3] then
Dialogue.Food3.SurfaceGui.Text.Text = game.Lighting.Food:FindFirstChild(FoodList[3]).FoodName.Value
Dialogue.Food3.ClickDetector2.MaxActivationDistance = 32
Dialogue.Food3.ClickDetector2.MouseClick:Connect(function()
local HealSound = game.Lighting.Assets.Battle.Heal:Clone()
HealSound.Parent = FightFolder
HealSound:Play()
CloseItemStuff()
MonsterCharacter.Main.Events.UseItem:Fire(tostring(FoodList[3]), Dialogue.MainText.SurfaceGui.Text)
game.Lighting.Food:FindFirstChild(FoodList[3]).Tool.Food.WhenHealed:Fire(Player)
FoodFolder:FindFirstChild(FoodList[3]).Value = FoodFolder:FindFirstChild(FoodList[3]).Value - 1
local success, fail = pcall(function()
table.remove(FoodList, table.find(FoodList, FoodInLighting.Name))
end)
wait(MonsterCharacter.Main.Values.TimeWaitForPass.Value + 1)
TakeAwayTurn()
return
end)
end
if FoodList[4] then
Dialogue.Food4.SurfaceGui.Text.Text = game.Lighting.Food:FindFirstChild(FoodList[4]).FoodName.Value
Dialogue.Food4.ClickDetector2.MaxActivationDistance = 32
Dialogue.Food4.ClickDetector2.MouseClick:Connect(function()
local HealSound = game.Lighting.Assets.Battle.Heal:Clone()
HealSound.Parent = FightFolder
HealSound:Play()
FoodFolder:FindFirstChild(FoodList[4]).Value = FoodFolder:FindFirstChild(FoodList[4]).Value - 1
CloseItemStuff()
MonsterCharacter.Main.Events.UseItem:Fire(tostring(FoodList[4]), Dialogue.MainText.SurfaceGui.Text)
game.Lighting.Food:FindFirstChild(FoodList[4]).Tool.Food.WhenHealed:Fire(Player)
local success, fail = pcall(function()
table.remove(FoodList, table.find(FoodList, FoodInLighting.Name))
end)
wait(MonsterCharacter.Main.Values.TimeWaitForPass.Value + 1)
TakeAwayTurn()
return
end)
end
if FoodList[5] then
Dialogue.Food5.SurfaceGui.Text.Text = game.Lighting.Food:FindFirstChild(FoodList[5]).FoodName.Value
Dialogue.Food5.ClickDetector2.MaxActivationDistance = 32
Dialogue.Food5.ClickDetector2.MouseClick:Connect(function()
local HealSound = game.Lighting.Assets.Battle.Heal:Clone()
HealSound.Parent = FightFolder
FoodFolder:FindFirstChild(FoodList[5]).Value = FoodFolder:FindFirstChild(FoodList[5]).Value - 1
HealSound:Play()
CloseItemStuff()
MonsterCharacter.Main.Events.UseItem:Fire(tostring(FoodList[5]), Dialogue.MainText.SurfaceGui.Text)
game.Lighting.Food:FindFirstChild(FoodList[5]).Tool.Food.WhenHealed:Fire(Player)
local success, fail = pcall(function()
table.remove(FoodList, table.find(FoodList, FoodInLighting.Name))
end)
wait(MonsterCharacter.Main.Values.TimeWaitForPass.Value + 1)
TakeAwayTurn()
return
end)
end
if FoodList[6] then
Dialogue.Food6.SurfaceGui.Text.Text = game.Lighting.Food:FindFirstChild(FoodList[6]).FoodName.Value
Dialogue.Food6.ClickDetector2.MaxActivationDistance = 32
Dialogue.Food6.ClickDetector2.MouseClick:Connect(function()
local HealSound = game.Lighting.Assets.Battle.Heal:Clone()
HealSound.Parent = FightFolder
FoodFolder:FindFirstChild(FoodList[6]).Value = FoodFolder:FindFirstChild(FoodList[6]).Value - 1
HealSound:Play()
CloseItemStuff()
MonsterCharacter.Main.Events.UseItem:Fire(tostring(FoodList[6]), Dialogue.MainText.SurfaceGui.Text)
game.Lighting.Food:FindFirstChild(FoodList[6]).Tool.Food.WhenHealed:Fire(Player)
local success, fail = pcall(function()
table.remove(FoodList, table.find(FoodList, FoodInLighting.Name))
end)
wait(MonsterCharacter.Main.Values.TimeWaitForPass.Value + 1)
TakeAwayTurn()
return
end)
end
if FoodList[7] then
Dialogue.Food7.SurfaceGui.Text.Text = game.Lighting.Food:FindFirstChild(FoodList[7]).FoodName.Value
Dialogue.Food7.ClickDetector2.MaxActivationDistance = 32
Dialogue.Food7.ClickDetector2.MouseClick:Connect(function()
local HealSound = game.Lighting.Assets.Battle.Heal:Clone()
HealSound.Parent = FightFolder
HealSound:Play()
CloseItemStuff()
FoodFolder:FindFirstChild(FoodList[7]).Value = FoodFolder:FindFirstChild(FoodList[7]).Value - 1
MonsterCharacter.Main.Events.UseItem:Fire(tostring(FoodList[7]), Dialogue.MainText.SurfaceGui.Text)
game.Lighting.Food:FindFirstChild(FoodList[7]).Tool.Food.WhenHealed:Fire(Player)
local success, fail = pcall(function()
table.remove(FoodList, table.find(FoodList, FoodInLighting.Name))
end)
wait(MonsterCharacter.Main.Values.TimeWaitForPass.Value + 1)
TakeAwayTurn()
return
end)
end
if FoodList[8] then
Dialogue.Food8.SurfaceGui.Text.Text = game.Lighting.Food:FindFirstChild(FoodList[8]).FoodName.Value
Dialogue.Food8.ClickDetector2.MaxActivationDistance = 32
Dialogue.Food8.ClickDetector2.MouseClick:Connect(function()
local HealSound = game.Lighting.Assets.Battle.Heal:Clone()
HealSound.Parent = FightFolder
HealSound:Play()
CloseItemStuff()
MonsterCharacter.Main.Events.UseItem:Fire(tostring(FoodList[8]), Dialogue.MainText.SurfaceGui.Text)
game.Lighting.Food:FindFirstChild(FoodList[8]).Tool.Food.WhenHealed:Fire(Player)
FoodFolder:FindFirstChild(FoodList[8]).Value = FoodFolder:FindFirstChild(FoodList[8]).Value - 1
local success, fail = pcall(function()
table.remove(FoodList, table.find(FoodList, FoodInLighting.Name))
end)
wait(MonsterCharacter.Main.Values.TimeWaitForPass.Value + 1)
TakeAwayTurn()
return
end)
end
wait(1)
FoodDebounce = false
end
Any help is appreciated! By the way if you need some more information about the script, go and ask! I’ll help as much as I can.