Hello, My script checks if certain conditions are met in a menu so it clicks them but its not updating properly the loops dont keep going unless i trigger the function again. I am honestly lost and have been trying to figure this out for 2 days.~~~~~~~~~~~~~~~~~
CompleteMission.MouseButton1Click:Connect(function()
CompleteMissionOn = not CompleteMissionOn
if CompleteMissionOn == true then
CompleteMission.TextColor3 = Color3.fromRGB(11, 221, 101)
else
CompleteMission.TextColor3 = Color3.fromRGB(255, 255, 255)
end
local function MineGemsOrGold(string)
if string == "GemOre5" and wait() and CompleteMissionOn == true then
game:GetService("ReplicatedStorage").GiveBonus:FireServer(5,5,2)
end
if string == "GoldOre8" and wait() and CompleteMissionOn == true then
game:GetService("ReplicatedStorage").GiveBonus:FireServer(5,5,1)
end
for i, v in pairs(game:GetService("Workspace").Ores:GetChildren()) do
if v.CanCollide == true and v.name == string and CompleteMissionOn == true then
fireclickdetector(v:FindFirstChildOfClass("ClickDetector"))
wait()
end
end
end
while true and wait() do -- Main loop
--gold and gems
if MissionStats.Mission1.value == 4 or MissionStats.Mission2.value == 4 or MissionStats.Mission3.value == 4 then
print("Gems = true")Gems = true
print("Gold = false")Gold = false
end
while Gems == true and Gold == false and wait() do
MineGemsOrGold("GemOre5")
end
if MissionStats.Mission1.value ~= 4 and MissionStats.Mission2.value ~= 4 and MissionStats.Mission3.value ~= 4 then
print("Gems = false")Gems = false
print("Gold = true")Gold = true
end
while Gold == true and Gems == false and wait() do
MineGemsOrGold("GoldOre8")
end
print(CompleteMissionOn)
-- mission 1
for i, v in pairs(MissionsToSkip) do
if MissionsGui.Mission1.Mission.Text:find(v) and MissionStats.MissionCooldown1.Value == 0 then
print("waiting to skip")
game:GetService("ReplicatedStorage").ResetMission:FireServer(1)
print("M1 skipped")
wait()
elseif
MissionsGui.Mission1.Mission.Text:find("runes") then
print("M1 = rune mission")
while MissionStats.MissionProgress1.Value ~= MissionStats.MissionGoal1.Value do
game:GetService("ReplicatedStorage").BuyRune2:FireServer(1)
wait()
end
elseif
MissionsGui.Mission1.Mission.Text:find("kryptonite") then
print("M1 = kryptonite mission")
while MissionStats.MissionProgress1.Value ~= MissionStats.MissionGoal1.Value and CompleteMissionOn == true and wait() do
for i, v in pairs(game:GetService("Workspace").Ores:GetChildren()) do
if v.CanCollide == true and v.name == "KryptoniteOre4" and CompleteMissionOn == true then
fireclickdetector(v:FindFirstChildOfClass("ClickDetector"))
wait()
end
end
end
elseif
MissionsGui.Mission1.Mission.Text:find("unobtainium") then
print("M1 = unobtainium mission")
while MissionStats.MissionProgress1.Value ~= MissionStats.MissionGoal1.Value and CompleteMissionOn == true and wait() do
for i, v in pairs(game:GetService("Workspace").Ores:GetChildren()) do
if v.CanCollide == true and v.name == "UnobtainiumOre4" and CompleteMissionOn == true then
fireclickdetector(v:FindFirstChildOfClass("ClickDetector"))
wait()
end
end
end
elseif
MissionsGui.Mission1.Mission.Text:find("uranium") then
print("M1 = uranium mission")
while MissionStats.MissionProgress1.Value ~= MissionStats.MissionGoal1.Value and CompleteMissionOn == true and wait() do
for i, v in pairs(game:GetService("Workspace").Ores:GetChildren()) do
if v.CanCollide == true and v.name == "UraniumOre5" and CompleteMissionOn == true then
fireclickdetector(v:FindFirstChildOfClass("ClickDetector"))
wait()
end
end
end
elseif
MissionsGui.Mission1.Mission.Text:find("silver") then
print("M1 = silver mission")
while MissionStats.MissionProgress1.Value ~= MissionStats.MissionGoal1.Value and CompleteMissionOn == true and wait() do
for i, v in pairs(game:GetService("Workspace").Ores:GetChildren()) do
if v.CanCollide == true and v.name == "SilverOre8" and CompleteMissionOn == true then
fireclickdetector(v:FindFirstChildOfClass("ClickDetector"))
end
end
end
end
if MissionStats.MissionProgress1.Value == MissionStats.MissionGoal1.Value then
game:GetService("ReplicatedStorage").ClaimMission:FireServer(1)
print ("M1 = claimed")
end
end
end
end)~~~~~~~~~~~~~~~~~
the gems and gold part is supposed to update the minegemsorgold function to mine either gems or gold depending on the missions that appear but the main loop only fires once and doesnt update the string that gets sent to the function. Also all the other loops below dont work while the gold and gems loops are running.

1 comment
check out task.spawn(), it spawns a new thread, functions in different threads are running independently on each other, here is an example: https://gist.github.com/kirdaaa/ef86fd9dbef1c40bcebbb7461c4bad51