Issue with food placing script

I’m trying to make pieces of food that can be collected with proximity prompts and I can stack them 0.25 studs over each other to make my own food but the problem is I want there to be a limit. I know that I can use a while loop or maybe a repeat until so that it can repeat/update itself to acquire the desired result but I don’t think that is the right way to script it. I’ve tried moving around the if statement which says if my part containing the proximity prompt that places the food parts is in a certain position, it will unenable the proximity prompt that brings food on the plate. This position is based on how much parts there are on the plate.

local part = workspace.PlateInteraction1
print(part.Position)
local rs = game:GetService("ReplicatedStorage")
local folder = rs.PartsFolder.PlacingParts
local placingfolder = workspace.PlacingPartsFolder:GetChildren()
part.ProximityPrompt.Triggered:Connect(function(plr)
	local num = -0.375
	local num2 = 0.25
	local char = plr.Character
	local tool = char:FindFirstChildWhichIsA("Tool")
	local handle = tool.Handle
	if tool.Name == "Meat" or "Lettuce" or "Cheese" then
		for i,v in pairs(folder:GetChildren()) do
			if v.Name == tool.Name then
				local foodpart = v:Clone()
				print("Cloned")
				if part.Position == part.Position then
					foodpart.Parent = workspace.PlacingPartsFolder
					foodpart.Position = part.Position + Vector3.new(0,num,0)
					part.Position = part.Position + Vector3.new(0,num2,0)
					tool:Destroy()
				else
					part.Position = Vector3.new(32.375,part.Position.Y + num2,15.25)
					foodpart.Position = part.Position
					foodpart.Position = foodpart.Position + Vector3.new(0,num,0)
				end
				if part.Position == Vector3.new(32.375, 6, 15.25) then
					part.ProximityPrompt.Enabled = false
				end
			end
		end
	end
end)

The project I’m working on if you don’t understand.

1 Like

Maybe try raycasting to the part that you want to stack your food on? I don’t really understand what you mean.

In the last if statement of the code, I’m trying to check if the part that triggers the position of the part that triggers the food spawning each certain amount of studs stored in a variable and if it is that amount I unenable the proximity prompt because that is its max. The main problem is that this line of code doesn’t work nor has nothing in the output, I’ve also moved this within the else statement and use the number of children in the placing parts folder to measure.

1 Like

Simplified: The last if statement is the reason my script cannot make a max of 4 food parts.

1 Like
while true do
	task.wait()
	local folder = workspace.PlacingPartsFolder:GetChildren()
	if #folder == 4 then
		workspace.PlateInteraction1.Enabled = false
	end
end

I could do this to fix my situation but the script is constantly running in order to perform such a simple task which seems incorrect to me. Is this proper or should I find another way to do this? If anyone is having trouble understanding I can publish the project i’m working on.

I found the solution to this script!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.