I am currently working on a small project called “burger”.
SUMMARY:
In this game, you essentially start in a Main Menu screen and click play. Your camera switches to a horizontal view. There is a 3 second countdown on screen. Then, a plate in the Workspace tweens in from the right. An order menu GUI for a burger also tweens in from the top right. The player then attempts to replicate the order of the burger as fast as they can with as much accuracy as then can. Based on their input, they get a score and earn points. The plate and the burger they created then tween to the left of their screen.
GOAL:
Currently, I have a variable checking if the player is doneMakingBurger. I have set it to false by default. There is then an if statement being looped by a while true do loop checking if the burger is done being made. If it is done being made(true), the script should continue and first check if a plate already exists. If the plate already exists in the Workspace, it will tween the plate off the left side of the player’s screen, move onto else, where a plate is cloned from ReplicatedStorage and tweened in from the right side of the player’s screen.
ISSUE:
For some reason, when I try to use the following code to detect if the part is there…
if workspace:FindFirstChild("Plate") then
-- code
end
AND/OR
if workspace:IsAncestorOf(Plate) then
-- code
end
… It doesn’t run the code on scenarios where the plate is there. In summary, the plate doesn’t tween away when it already exists, so I end up with a bunch of plates. To better understand the issue, below I have linked some resources:
CODE: LocalScript, located in ReplicatedFirst.
local rps = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local ts = game:GetService("TweenService")
local food = rps:WaitForChild("Food")
local plate = food.Plate
local bread = rps.Food.Bread
local meat = rps.Food.Meat
local lettuce = rps.Food.Lettuce
local tomato = rps.Food.Tomato
local MenuGui = player.PlayerGui:WaitForChild("MenuGui")
local playbutton = MenuGui.Background.Frame:WaitForChild("PlayButton")
local doneMakingBurger = false -- set to false
local partName = "Plate"
local foundPart = workspace:FindFirstChild(partName) -- should check if the part exists
print(player.PlayerGui.Parent.Name)
playbutton.MouseButton1Click:Connect(function()
wait(.2)
doneMakingBurger = true
end)
while true do
wait(.01)
if doneMakingBurger == true then
doneMakingBurger = false
if foundPart then
local oldPlate = game.Workspace:WaitForChild("Plate") -- skips this part, not sure why
local oldGoal = {}
oldGoal.Position = Vector3.new(-45, 0.5, -31.224)
local oldTweenInfo = TweenInfo.new(1.2, Enum.EasingStyle.Quad)
local plateTweenOut = ts:Create(oldPlate, oldTweenInfo, oldGoal)
plateTweenOut:Play()
oldPlate:Destroy()
local newPlate = plate:Clone()
newPlate.Position = Vector3.new(45, 0.5, -31.224)
newPlate.Anchored = true
newPlate.Parent = game.Workspace
local newGoal = {}
newGoal.Position = Vector3.new(0, 0.5, -31.224)
local newTweenInfo = TweenInfo.new(1.2, Enum.EasingStyle.Quad)
local plateTweenIn = ts:Create(newPlate, newTweenInfo, newGoal)
plateTweenIn:Play()
else
local newPlate = plate:Clone()
newPlate.Position = Vector3.new(45, 0.5, -31.224)
newPlate.Anchored = true
newPlate.Parent = game.Workspace
local newGoal = {}
newGoal.Position = Vector3.new(0, 0.5, -31.224)
local newTweenInfo = TweenInfo.new(1.2, Enum.EasingStyle.Quad)
local plateTweenIn = ts:Create(newPlate, newTweenInfo, newGoal)
plateTweenIn:Play()
doneMakingBurger = false
for i = 5, 0, -1 do -- added a countdown that will show up in the output to check if the script detects the new plate
print(i)
wait(1)
end
doneMakingBurger = true
end
end
-- plate present pos (tween to) 0, 0.5, -31.224 (vector)
-- plate before pos (tween from) 45, 0.5, -31.224
end
Any input/help is appreciated. I have tried doing research to no avail. I appreciate everyone’s time!
(If you feel like doing a little extra or don’t know the solution and still want to help, I would also appreciate some feedback on how I’m formatting my scripts. Let me know if it’s too spaced out, has good readability, etc. Thank you for your feedback!)