Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make it where you can accidentally burn food when cooking?

Asked by 5 years ago
Edited 5 years ago

I am making a cooking game and I want to make it where if you click it in time, then it gives you a bacon tool or something, but if you don't, in five seconds, it will burn. I already made the burning part but I don't know how to make it where, like I said, if you don't get it in five seconds then it happens. Thanks!

Here is the script:

function onClicked()

local ToolNames = {"CookedBacon", "Item", "Item"}-----put name of the tool has to be exact exact name (remove the words items but not (") keep (")Between (" ") put item name for EX: "Glock 17"
local Storage = game:GetService("ServerStorage")----Put the tool item in serverstorage (cars,hats,and clothing will not work only tools work like guns and such)


local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")

ClickDetector.MouseClick:connect(function(Player)
    if Player and Player.Character then
        local Backpack = Player:WaitForChild("Backpack")
        for i = 1, #ToolNames do
            local Tool = Storage:FindFirstChild(ToolNames[i])
            if Tool then
                Tool:clone().Parent = Backpack
                script.Parent.Transparency = 1
                script.Parent.SurfaceGui.Enabled = false
                script.Parent.Parent.Transparency = 1
                script.Parent.Parent.Baconn.Transparency = 1
            else
                wait(3)
                script.Parent.SurfaceGui.TextLabel.Text = "BURNT"
                script.Parent.Parent.BurntBacon.Transparency = 0
                script.Parent.Parent.BurntBacon.Smoke.Enabled = true
                script.Parent.Parent.Baconn.Transparency = 1

            end
        end
    end
end)



end 
  script.Parent.ClickDetector.MouseClick:connect(onClicked)

1
Padme change 'corutine' to 'coroutine' . Maum made a typo. 123nabilben123 499 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

You can use coroutines to make a wait and not pause the thread (or just put the wait at the end)

Also, using MouseClick will always do a new function and putting a wait wont work.

Use this code:

local connection
function onClicked()

local ToolNames = {"CookedBacon", "Item", "Item"}-----put name of the tool has to be exact exact name (remove the words items but not (") keep (")Between (" ") put item name for EX: "Glock 17"
local Storage = game:GetService("ServerStorage")----Put the tool item in serverstorage (cars,hats,and clothing will not work only tools work like guns and such)


local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
local alreadyFinished = false --// a way to know if the player has already clicked
coroutine.resume(corutine.create(function()

                wait(3)
if alreadyFinished == false then
                script.Parent.SurfaceGui.TextLabel.Text = "BURNT"
                script.Parent.Parent.BurntBacon.Transparency = 0
                script.Parent.Parent.BurntBacon.Smoke.Enabled = true
                script.Parent.Parent.Baconn.Transparency = 1
end
end))
ClickDetector.MouseClick:connect(function(Player)
    if Player and Player.Character then
        local Backpack = Player:WaitForChild("Backpack")
        for i = 1, #ToolNames do
            local Tool = Storage:FindFirstChild(ToolNames[i])
            if Tool then
                Tool:clone().Parent = Backpack
                script.Parent.Transparency = 1
                script.Parent.SurfaceGui.Enabled = false
                script.Parent.Parent.Transparency = 1
                script.Parent.Parent.Baconn.Transparency = 1
alreadyFinished = true

            end
        end
    end
end)



end 
  connection = script.Parent.ClickDetector.MouseClick:Connect(onClicked) -- connect is deprecated use Connect instead

0
Thanks, I'll try this out! PadmeOragana 78 — 5y
0
I tried it and it doesn't work. I think it's because it is because when I go over "corutine" it says "W001 Unknown Global 'corutine'. Solution? PadmeOragana 78 — 5y
1
Padme change 'corutine' to 'coroutine' . Maum made a typo. 123nabilben123 499 — 5y
0
Thank you 123nabilben123! PadmeOragana 78 — 5y
Ad

Answer this question