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:

01function onClicked()
02 
03local 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"
04local Storage = game:GetService("ServerStorage")----Put the tool item in serverstorage (cars,hats,and clothing will not work only tools work like guns and such)
05 
06 
07local Part = script.Parent
08local ClickDetector = Part:WaitForChild("ClickDetector")
09 
10ClickDetector.MouseClick:connect(function(Player)
11    if Player and Player.Character then
12        local Backpack = Player:WaitForChild("Backpack")
13        for i = 1, #ToolNames do
14            local Tool = Storage:FindFirstChild(ToolNames[i])
15            if Tool then
View all 36 lines...
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:

01local connection
02function onClicked()
03 
04local 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"
05local Storage = game:GetService("ServerStorage")----Put the tool item in serverstorage (cars,hats,and clothing will not work only tools work like guns and such)
06 
07 
08local Part = script.Parent
09local ClickDetector = Part:WaitForChild("ClickDetector")
10local alreadyFinished = false --// a way to know if the player has already clicked
11coroutine.resume(corutine.create(function()
12 
13                wait(3)
14if alreadyFinished == false then
15                script.Parent.SurfaceGui.TextLabel.Text = "BURNT"
View all 42 lines...
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