The point of the hibachi script is that it gets food from the FoodItems folder and it uses texture to create like a small pop out in the gui (frame) to choose which food to cook. But it wont open the gui or anything which should open main frame and do the rest.
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local CookingGui = ReplicatedStorage:FindFirstChild(“CookingGui”)
local CookingMini = ReplicatedStorage:FindFirstChild(“CookingMinigame”)
local TweenService = game:GetService(“TweenService”)
local Players = game:GetService(“Players”)
local hibachi = script.Parent
local grill = hibachi.Grill
local proximity = grill.ProximityPrompt
local teleportPart = hibachi.TeleportPart
local FirePart = hibachi.FirePart.Fire
local FireGoal = hibachi.EndGoal
local originalFirePartCFrame = FirePart.Parent.CFrame
local connections = {}
– store the last player object who interacted
local playerLastInteraction = nil
local lastShelfProximity = nil
– TODO: on player leave remove their connection
local RemoveClient = ReplicatedStorage:WaitForChild(“RemoveClient”)
local function cleanupConnections()
warn(connections)
for key, connection in pairs(connections) do
if typeof(connection) == “RBXScriptConnection” and connection.Connected then
connection:Disconnect()
–warn(“is .Connected?”, connection.Connected)
elseif typeof(connection) == “Instance” then
connection:Destroy()
end
connections[key] = nil
end
playerLastInteraction = nil
warn(connections)
end
local function reset_grill(player: Player)
local playerCharacter = player.Character or player.CharacterAdded:Wait()
playerCharacter.PrimaryPart.Anchored = false
FirePart.Enabled = false
playerLastInteraction = nil
–cookProximity:Destroy() removed by connection servicing
–shelfProximity.Enabled = false may be a future bug
proximity.Enabled = true
if lastShelfProximity ~= nil then
lastShelfProximity.Enabled = false
end
FirePart.Parent.CFrame = originalFirePartCFrame
playerLastInteraction = nil
–connections[player]:Disconnect()
–connections[player] = nil
local cleanup = {“clonedGotoBeam”, “attachment0”, “attachment1”}
for index, value in pairs(cleanup) do
if connections[value] ~= nil then
connections[value]:Destroy()
connections[value] = nil
end
end
end
RemoveClient.OnServerEvent:Connect(function(player: Player)
warn(“pressed exit button”)
local PlayerGui = player:WaitForChild(“PlayerGui”)
for _, gui in pairs(PlayerGui:GetChildren()) do
if gui.Name == “CookingGui” or “CookingMinigame” then
gui:Destroy()
end
end
cleanupConnections()
reset_grill(player)
end)
Players.PlayerAdded:Connect(function(player: Player)
player.CharacterRemoving:Connect(function(character)
warn(“cleanup character conncections”)
cleanupConnections()
reset_grill(player)
end)
end)
Players.PlayerRemoving:Connect(function(player: Player)
warn(player.Name, “Left the game and triggered a cleanup”)
cleanupConnections()
reset_grill(player)
end)
local function findClosestShelf(Hibachi:Model, Shelves:Model): Model
local closestShelf = nil
local closestDistance = math.huge
for _, shelf in pairs(Shelves:GetChildren()) do
if shelf:IsA(“Model”) and shelf.PrimaryPart ~= nil and Hibachi.PrimaryPart ~= nil then
local distance = (Hibachi.PrimaryPart.Position - shelf.PrimaryPart.Position).Magnitude
if distance < closestDistance then
closestShelf = shelf
closestDistance = distance
end
end
warn(closestShelf, closestDistance)
end
return closestShelf
end
local function selectCallback(player:Player, dish:string, …)
warn(player, dish, …)
–proximity.Enabled = false Multiplayer fix
local playerCharacter = player.Character
local HumanoidRootPart = playerCharacter:FindFirstChild(“HumanoidRootPart”)
local Humanoid = playerCharacter:FindFirstChildOfClass(“Humanoid”)
local Animator:Animator = Humanoid:WaitForChild(“Animator”)
playerCharacter.PrimaryPart.Anchored = true
playerCharacter:PivotTo(teleportPart:GetPivot() * CFrame.new(0, 2.9, 0))
– play animation
local OilPourAnimation = ReplicatedStorage.Animations.OilPour
local animationTrack = Animator:LoadAnimation(OilPourAnimation)
animationTrack:Play(1, 1, 0.55)
– Start fire effect
task.wait(3)
FirePart.Parent.CFrame = originalFirePartCFrame
FirePart.Enabled = true
local FireMovement = TweenService:Create(FirePart.Parent, TweenInfo.new(2), {CFrame = FireGoal.CFrame})
FireMovement:Play()
task.wait(2)
playerCharacter.PrimaryPart.Anchored = false
– find a random shelf and create that beam effect
local shelvesObject = hibachi.ConnectedShelves.Value
local TargetShelf = findClosestShelf(hibachi, shelvesObject)
–local TargetShelf = shelvesObject.Shelf
–local TargetShelves = shelvesObject:GetChildren()
–local TargetShelf = TargetShelves[math.random(1, #TargetShelves)]
local clonedGotoBeam = ReplicatedStorage:WaitForChild(“GotoBeam”):Clone()
clonedGotoBeam.Parent = HumanoidRootPart
if HumanoidRootPart ~= nil and TargetShelf.PrimaryPart ~= nil then
warn(“attaching beam object”)
local attachment0 = Instance.new("Attachment", playerCharacter.PrimaryPart)
attachment0.Name = "Attachment0"
local clonedGotoBeam = ReplicatedStorage:WaitForChild("GotoBeam"):Clone()
clonedGotoBeam.Parent = playerCharacter.PrimaryPart
clonedGotoBeam.Enabled = true
local attachment1 = Instance.new("Attachment", TargetShelf.PrimaryPart)
attachment1.Name = "Attachment1"
clonedGotoBeam.Attachment0 = attachment1
clonedGotoBeam.Attachment1 = attachment0
connections["clonedGotoBeam"] = clonedGotoBeam;
connections["attachment0"] = attachment0;
connections["attachment1"] = attachment1;
-- skipping that
local shelfProximity:ProximityPrompt = TargetShelf.PrimaryPart:WaitForChild("ProximityPrompt")
shelfProximity.Enabled = true
lastShelfProximity = shelfProximity
--warn(shelfProximity:GetFullName())
local chosenGear = ReplicatedStorage.FoodItems[dish]:Clone()
-- add this to the connection list instead
connections["shelfProximity"] = shelfProximity.Triggered:Connect(function(player)
if playerLastInteraction == player then
chosenGear.Parent = player.Backpack
shelfProximity.Enabled = false
connections["shelfProximity"]:Disconnect()
-- remove stuff
connections["clonedGotoBeam"]:Destroy()
connections["attachment0"]:Destroy()
connections["attachment1"]:Destroy()
end
end)
-- create a new proximity prompt on the grill called "cook"
proximity.Enabled = false -- disable the old proximity prompt
local cookConnection = nil
local cookProximity = Instance.new("ProximityPrompt", grill)
cookProximity.ActionText = "Cook "..dish
cookProximity.ObjectText = "Grill"
table.insert(connections, cookProximity)
cookConnection = cookProximity.Triggered:Connect(function(player)
-- we need to know if they have the tool out
-- otherwise throw an error message
local playerCharacter = player.Character
if playerLastInteraction == player then
local foundGear = playerCharacter:FindFirstChild(chosenGear.Name)
if foundGear ~= nil and foundGear == chosenGear then
-- player has the tool out, lets now cook
warn("cooking food now")
playerCharacter.PrimaryPart.Anchored = true
playerCharacter:PivotTo(teleportPart:GetPivot() * CFrame.new(0, 2.9, 0))
-- now to clone that minigame and bind to get the result
local clonedMinigame = ReplicatedStorage.CookingMinigame:Clone()
local foundRemote = clonedMinigame:FindFirstChild("CompletedMinigame")
local PlayerGui = player:FindFirstChild("PlayerGui")
local foundGui = PlayerGui:FindFirstChild(clonedMinigame.Name)
if foundGui == nil then
clonedMinigame.Parent = PlayerGui
else
foundGui.Enabled = true
end
local remoteConnection = nil
remoteConnection = foundRemote.OnServerEvent:Once(function()
-- they at this point have destroyed the gui
-- now we are supposed to give them a new item
warn("won the game lol")
for _, gui in pairs(PlayerGui:GetChildren()) do
if gui.Name == "CookingGui" or "CookingMinigame" then
gui:Destroy()
end
end
playerCharacter.PrimaryPart.Anchored = false
FirePart.Enabled = false
playerLastInteraction = nil
cookProximity:Destroy()
shelfProximity.Enabled = false
proximity.Enabled = true
FirePart.Parent.CFrame = originalFirePartCFrame
playerLastInteraction = nil
connections[player]:Disconnect()
connections[player] = nil
remoteConnection:Disconnect()
remoteConnection = nil
end)
end
end
end)
else
warn(“conditions not satisfied”)
end
–cleanupConnections()
end
local function GetFoodItems(): {}
local FoodItems = ReplicatedStorage.FoodItems
local result = {}
for _, item in pairs(FoodItems:GetChildren()) do
if item:IsA(“Tool”) and item:FindFirstChildOfClass(“StringValue”) then
local TextureId = item.Texture
result[item.Name] = TextureId.Value
end
end
return result
end
proximity.Triggered:Connect(function(player: Player)
warn(player.Name)
warn(connections)
– no one has used this before or has left
if not playerLastInteraction and player:IsInGroup(35411958) and player:GetRankInGroup(35411958) >= 3 then
warn(“is in group”)
local playerGui = player:FindFirstChild(“PlayerGui”)
playerLastInteraction = player
-- give the gui to the player
-- remove any previous guis we dont want
for _, item in pairs(playerGui:GetChildren()) do
if item.Name == CookingGui.Name or item.Name == CookingMini.Name then
item:Destroy()
end
end
if connections[player] == nil then
local clonedGui = CookingGui:Clone()
clonedGui.Parent = playerGui
clonedGui.Enabled = true
local updateEvent = clonedGui:FindFirstChild("GetDishes")
local updateFoodConnection = nil
updateFoodConnection = updateEvent.OnServerEvent:Once(function(player)
warn("firing back to client response")
local foodItems = GetFoodItems()
updateEvent:FireClient(player, foodItems)
warn(foodItems)
updateFoodConnection:Disconnect()
updateFoodConnection = nil
end)
-- find our trigger and bind onserverevent
local selectEvent = clonedGui:FindFirstChild("SelectDish")
connections[player] = selectEvent.OnServerEvent:Once(selectCallback)
end
else
– player walked away, task.delay this sep thread for timeout
end
end)