I personally believe this might have taken me too long and too many lines of code in order to make a functioning coffee and tea handler, with different flavors and what not.
So, how is it? How could I make this more efficient, or even shorter to script?
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local cookingObjectFolder = workspace.CookingObjects
local blenderFolder = cookingObjectFolder:WaitForChild('Blender')
local teaFlavorFolder = cookingObjectFolder:WaitForChild('TeaFlavor')
local coffeeFolder = cookingObjectFolder:WaitForChild('Coffee')
local waterFolder = cookingObjectFolder:WaitForChild('Water')
local milkFolder = cookingObjectFolder:WaitForChild('Milk')
local cupFolder = cookingObjectFolder:WaitForChild('Cup')
local iceFolder = cookingObjectFolder:WaitForChild('Ice')
local whippedCreamFolder = cookingObjectFolder:WaitForChild('WhippedCream')
local itemFolder = ReplicatedStorage:WaitForChild('Items')
local debounce = false
local hb = 1
local machineTime = 3
wait(machineTime)
local function visualEffects(tool, hitbox)
tool.Visual1.Color = hitbox.Color
tool.Visual1.Transparency = 0
end
local function coffeeMachineVisualizer(v, hitPart)
v.Parent.Liquid.Transparency = 0
for _, k in pairs(v.Parent.CupVisual:GetChildren()) do
k.Transparency = 0.6
end
local char = hitPart.Parent.Parent
local plr = Players:GetPlayerFromCharacter(char)
hitPart.Parent.Parent = game.Lighting
wait(machineTime)
hitPart.Parent.Parent = plr.Backpack
for _, k in pairs(v.Parent.CupVisual:GetChildren()) do
k.Transparency = 1
end
v.Parent.Liquid.Transparency = 1
end
for _, v in pairs(cupFolder:GetDescendants()) do
if v:IsA('ProximityPrompt') then
v.Triggered:Connect(function(player)
if not player.Character:FindFirstChild('Cup') and not player.Backpack:FindFirstChild('Cup') then
local cupClone = itemFolder.Cup:Clone()
cupClone.Parent = player.Backpack
end
end)
end
end
for _, v in pairs(iceFolder:GetDescendants()) do
if v.Name == "Hitbox" then
local iceDebounce = false
v.Touched:Connect(function(hitPart)
if not iceDebounce and hitPart.Parent:IsA('Tool') then
local nameCheck = string.sub(hitPart.Parent.Name, 0, 4)
if nameCheck ~= "Iced" then
hitPart.Parent.Name = "Iced "..hitPart.Parent.Name
for _, ice in pairs(hitPart.Parent.Cup:GetChildren()) do
if ice:IsA("Part") then
ice.Transparency = 0
end
end
end
RunService.Heartbeat:Wait(hb)
iceDebounce = true
end
end)
end
end
for _, v in pairs(coffeeFolder:GetDescendants()) do
if v.Name == "Hitbox" then
local coffeDebounce = false
v.Touched:Connect(function(hitPart)
if not debounce and hitPart.Parent:IsA('Tool') then
coffeDebounce = true
if hitPart.Parent.Name == "Cup" then
hitPart.Parent.Name = v.Parent.Name..' Coffee'
coffeeMachineVisualizer(v, hitPart)
visualEffects(hitPart.Parent, v)
elseif hitPart.Parent.Name == "Hot Milk" then
if v.Parent.Name == "Espresso" then
hitPart.Parent.Name = "Cappuccino"
end
if v.Parent.Name == "Regular" then
hitPart.Parent.Name = "Frappuccino"
end
coffeeMachineVisualizer(v, hitPart)
visualEffects(hitPart.Parent, v)
end
RunService.Heartbeat:Wait(hb)
coffeDebounce = false
end
end)
end
end
for _, v in pairs(teaFlavorFolder:GetDescendants()) do
if v.Name == "Hitbox" then
local teaDebounce = false
v.Touched:Connect(function(hitPart)
if not debounce and hitPart.Parent:IsA('Tool') then
if hitPart.Parent.Name == "Hot Water" then
teaDebounce = true
hitPart.Parent.Name = v.Parent.Name.." Tea"
visualEffects(hitPart.Parent, v)
RunService.Heartbeat:Wait(hb)
teaDebounce = false
end
end
end)
end
end
for _, v in pairs(waterFolder:GetDescendants()) do
if v.Name == "Hitbox" then
local waterDebounce = false
v.Touched:Connect(function(hitPart)
if not waterDebounce and hitPart.Parent:IsA('Tool') then
waterDebounce = true
if hitPart.Parent.Name == "Cup" then
if v.Parent.Name == "HotWater" then
hitPart.Parent.Name = "Hot Water"
elseif v.Parent.Name == "Water" then
hitPart.Parent.Name = "Water"
end
visualEffects(hitPart.Parent, v)
end
RunService.Heartbeat:Wait(hb)
waterDebounce = false
end
end)
end
end
for _, v in pairs(milkFolder:GetDescendants()) do
if v.Name == "Hitbox" then
local milkDebounce = false
v.Touched:Connect(function(hitPart)
if not milkDebounce and hitPart.Parent:IsA('Tool') then
milkDebounce = true
if hitPart.Parent.Name == "Cup" then
if v.Parent.Name == "HotMilk" then
hitPart.Parent.Name = "Hot Milk"
elseif v.Parent.Name == "Milk" then
hitPart.Parent.Name = "Milk"
end
visualEffects(hitPart.Parent, v)
end
RunService.Heartbeat:Wait(hb)
milkDebounce = false
end
end)
end
end
for _, v in pairs(whippedCreamFolder:GetDescendants()) do
if v.Name == "Hitbox" then
local whippedCreamedDebounce = false
v.Touched:Connect(function(hitPart)
if not whippedCreamedDebounce and hitPart.Parent:IsA('Tool') then
whippedCreamedDebounce = true
hitPart.Parent.WhippedCream.Transparency = 0
hitPart.Parent.Cover:Destroy()
hitPart.Parent.Name = hitPart.Parent.Name.." w/ Cream"
RunService.Heartbeat:Wait(hb)
whippedCreamedDebounce = false
end
end)
end
end