For some reason, Stage 2 is firing even though I didnt click it twice. What is the problem here?
local CookGuis = {}
local DB = false
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
local Cook
if not CookGuis[plr.UserId] then
Cook = script.Parent.Parent.Cook:Clone()
CookGuis[plr.UserId] = Cook
else
Cook = CookGuis[plr.UserId]
end
local suc, err = pcall(function()
if plr.Character:FindFirstChildWhichIsA("Tool") or Cook.isCooking.Value == true or Cook.CookFrame.Cook.Text == "GET" or Cook.CookFrame.Cook.Text == "STOP" then
print(CookGuis)
if plr.Character:FindFirstChildWhichIsA("Tool") then
Cook:WaitForChild("Source", 10).Value = script.Parent.Parent
Cook.CookFrame:WaitForChild("CookedItem", 10).Value = game.ReplicatedStorage.CookedItems:FindFirstChild(plr.Character:FindFirstChildWhichIsA("Tool").Name)
end
Cook.Parent = plr.PlayerGui
Cook.Enabled = true
Cook.CookFrame.ItemName.Text = plr.Character:FindFirstChildWhichIsA("Tool").Name
Cook.CookFrame.Exit.MouseButton1Down:Connect(function()
Cook.Enabled = false
end)
Cook.CookFrame.Cook.MouseButton1Down:Connect(function()
print("Pressing and stage is ".. Cook.Stage.Value)
local tool = plr.Character:FindFirstChildWhichIsA("Tool")
if tool then
print("stage: ".. Cook.Stage.Value)
local Amount = tool:GetAttribute("Amount")
local AmountC = 0
local ToolClone = tool:Clone()
wait(0.4)
if Cook.Stage.Value == 2 then
print("Stopping")
print(Cook.Stage.Value)
Cook.isCooking.Value = false
Cook.Stage.Value = 3
Cook.CookFrame.Cook.Text = "GET"
end
if Cook.Stage.Value == 1 then
local Handle = tool:FindFirstChild("Handle"):Clone()
Handle.Parent = script.Parent
tool:Destroy()
Handle.CFrame = script.Parent.CFrame
Handle.Anchored = true
Cook:WaitForChild("isCooking", 10).Value = true
Cook.CookFrame.Cook.Text = "STOP"
Cook.Stage.Value += 1
wait(0.5)
local amountCooked = Cook.Cook:InvokeClient(plr, tool, "COOK")
AmountC = amountCooked
Cook.CookFrame.Cook.Text = "GET"
Cook.Stage.Value += 1
script.Parent:FindFirstChild("Handle"):Destroy()
local newTool = Cook.CookFrame.CookedItem.Value:Clone()
local newHandle = newTool:FindFirstChild("Handle"):Clone()
newTool:Destroy()
newHandle.Parent = script.Parent
newHandle.CFrame = script.Parent.CFrame
newHandle.Anchored = true
elseif Cook.Stage.Value == 3 then
local NewItem = Cook.CookFrame.CookedItem.Value:Clone()
if AmountC > 0 then
NewItem:SetAttribute("Amount", AmountC)
NewItem.Parent = plr.Backpack
end
print(Amount.. " and ".. AmountC)
if Amount > AmountC then
ToolClone:SetAttribute("Amount", Amount - AmountC)
ToolClone.Parent = plr.Backpack
else
ToolClone:Destroy()
end
Cook.isCooking.Value = false
Cook.CookFrame.Cook.Text = "COOK"
Cook.Stage.Value = 1
end
end
end)
end
end)
if err then
warn(err)
end
end)