So I’m making taco machines and am currently in the process of testing the meat dropper but when the first batch of tacos (two) get meat, the game starts lagging A TON. So I’m thinking it’s a problem with the script.
Here it is:
script.Parent.Touched:Connect(function(hit)
if hit.Name == "Taco" then -- hit is taco
for i, v in pairs(hit.Parent.Meat:GetChildren()) do
if v.Name ~= "Part" then
v.Transparency = 0
end
wait()
end
elseif hit.Parent.Parent:FindFirstChild("Taco") then -- hit is part of meat
for i, v in pairs(hit.Parent:GetChildren()) do
if v.Name ~= "Part" then
v.Transparency = 0
end
wait()
end
end
end)
elseif hit.Parent.Parent:FindFirstChild("Taco") then -- hit is part of meat
for i, v in pairs(hit.Parent:GetChildren()) do
if v.Name ~= "Part" then
v.Transparency = 0
end
wait()
end
end
Look like this:
elseif hit.Parent and hit.Parent.Parent and hit.Parent.Parent.Name == "Taco" then -- hit is part of meat
for i, v in pairs(hit.Parent:GetChildren()) do
if v.Name ~= "Part" then
v.Transparency = 0
end
end
end
I tried to reproduce and fix your case in an empty place, feel free to testrun it. tacomeat.rbxl (19.1 KB)
local FallingMeat = script.Parent
local Taco
local TouchedConnection
function onTacoModelTouched(hit)
if hit.Name == "Taco" then -- hit is taco
Taco = hit
for _, v in pairs(Taco.Parent.Meat:GetChildren()) do
if v:IsA("BasePart") or v:IsA("UnionOperation") or v:IsA("MeshPart") then
v.Transparency = 0
end
end
elseif hit.Parent.Parent:FindFirstChild("Taco") then -- hit is part of meat
Taco = hit.Parent.Parent.Taco
for _, v in pairs(Taco:GetChildren()) do
if v:IsA("BasePart") or v:IsA("UnionOperation") or v:IsA("MeshPart") then
v.Transparency = 0
end
end
end
--print("done")
Touchedconnection:Disconnect()
end
Touchedconnection = FallingMeat.Touched:Connect(onTacoModelTouched)
Your current code creates lag because the Touched event fires for every miniscule movement a part makes against another part, even if it has already changed the intended set of parts’ transparency. Disconnecting this event would be useful for preventing lag caused by that.
I didn’t want to change things too much since I don’t know all the details of your setup, but this should work.
local taco
local connection
connection = script.Parent.Touched:Connect(function(hit)
if hit.Name == "Taco" then -- hit is taco
taco = hit.Parent
for i, v in pairs(taco.Meat:GetChildren()) do
wait()
if v.Name ~= "Part" then
v.Transparency = 0
end
end
elseif hit.Parent.Parent:FindFirstChild("Taco") then -- hit is part of meat
taco = hit.Parent.Parent
for i, v in pairs(taco.Meat:GetChildren()) do
wait()
if v.Name ~= "Part" then
v.Transparency = 0
end
end
end
print("Finished")
connection:Disconnect()
end)
Somehow this didn’t do anything, even with
I got rid of the debounce but now I’m thinking it should be put back, because “Finished” comes in the output 52 times with only two tacos.
Also if I get rid of wait() then only one taco gets meat…
I have found out that the unions are ONE of the antagonists. I have no idea why, since the unions are now meshes, it’s not laggy anymore but this happens:
I think the other antagonist is this script located in the taco shell dropper:
local tacos = script.Parent.Tacos
local tacoFolder = workspace.Tacos
local tweenServ = game:GetService("TweenService")
local tInfo = TweenInfo.new(1,Enum.EasingStyle.Quint,Enum.EasingDirection.Out,0,false,0)
while true do
wait(2)
--getting tacos coming out
local nextTacos = {}
local tacoTable = {}
for i, v in pairs(tacos:GetChildren()) do
if v.Name == "NextTaco" then
table.insert(nextTacos, v)
elseif v.Name == "Taco" then
tacoTable[v] = v.Taco.Position
end
local newTween = tweenServ:Create(v.Taco, tInfo, {
CFrame = v.Taco.CFrame + Vector3.new(2, 0, 0)
})
newTween:Play()
end
wait(1.5)
for _, nextTaco in pairs(nextTacos) do
nextTaco.Taco.Anchored = false
nextTaco.Parent = tacoFolder
nextTaco.Name = "IAmPinleon's Taco"
nextTacos = {}
end
wait(.5)
for i, v in pairs(tacoTable) do
local newTaco = i:Clone()
newTaco.Parent = tacos
newTaco.Taco.Position = v
i.Name = "NextTaco"
end
end
I think the tween or making it unanchored has to do something with it.