While Loop works but not Function

  1. What do you want to achieve?
    I want to fix my script.

  2. What is the issue?
    The issue is that I don’t know how to fix it.

  3. What solutions have you tried so far?
    I tried getting help from HiddenDevs but they just send emojis…

Script:

--// Services
local Services = {
    Players = game:GetService("Players");
    ReplicatedStorage = game:GetService("ReplicatedStorage");
    TweenService = game:GetService("TweenService");
}

--// DropperSettings
local MaxIngredientsToDrop = 4
local Ingredient = Services.ReplicatedStorage.Ingredients:FindFirstChild("Chocolate")
local MixTime = 1
local DroppingCooldown = 3

--// Bools
local IsBlending = false
local CanDrop = true
local CanBlend = false

--// Dropper
local DropperPart = script.Parent.DropperPart

--// MixPart
local MixPart = script.Parent.MixPart

--// Buttons
local StartButton = script.Parent.StartButton

--// Proximity
local StartProximity = StartButton.Blend

--// Tween Info
local MixTweenSettingsStart = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut, 0, false, 0) -- Time, EasingStyle, EasingDirection, Repeat, Reverses, Delay
local MixTweenSettingsEnd = TweenInfo.new(1, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut, 0, false, 0) -- Time, EasingStyle, EasingDirection, Repeat, Reverses, Delay

--// Functions
local numParts = 0

local function startBlending()
    StartProximity.Enabled = false
    IsBlending = true

    Services.TweenService:Create(MixPart, MixTweenSettingsStart, {["Size"] = Vector3.new(14.546, 10.299, 12.963)}):Play()
    wait(MixTweenSettingsStart.Time)
    Services.TweenService:Create(MixPart, MixTweenSettingsEnd, {["Size"] = Vector3.new(0.001, 10.299, 12.963)}):Play()
    wait(MixTweenSettingsEnd.Time)

    IsBlending = false
    StartProximity.Enabled = true
end

StartProximity.Triggered:Connect(function()
    if CanDrop and CanBlend and not IsBlending then
        startBlending()
    end
end)

while wait(DroppingCooldown) do

    numParts = #script.Parent.Ingredients:GetChildren()

    if numParts == MaxIngredientsToDrop then
        CanDrop = false
        CanBlend = true
    elseif numParts < MaxIngredientsToDrop and IsBlending == false then
        CanDrop = true
        CanBlend = false
        local IngredientNew = Ingredient:Clone()
        IngredientNew.Parent = script.Parent.Ingredients
        IngredientNew.Position = DropperPart.Position
    end
end

I do not get any errors. The only thing that works perfectly is the while loop. The function for blending doesn’t work.

how come the size is in [] brackets? This might be your issue.

Also, interesting method with using a table for services. I’ve never done that before.

One more thing - I know what I’m about to say isn’t commonly done, but for bool values, which in your case are essentially for debounce, I use actual bool values, and parent them to the script at hand.

The whole function doesn’t work.

Your function probably works but it looks like you purposely designed the if statement to not comply with the bools you have assigned in the while loop. If something doesn’t work, you should test the condition statements to make sure it’s initially getting past them in the first place.

if CanDrop and CanBlend and not IsBlending then

if numParts == MaxIngredientsToDrop then
        CanDrop = false
        CanBlend = true
elseif numParts < MaxIngredientsToDrop and IsBlending == false then
        CanDrop = true
        CanBlend = false
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.