Here is the script that spawns the eggs at the top of the hill.
local EggFolder = Instance.new("Folder")
EggFolder.Name = "EggFolder"
EggFolder.Parent = game.Workspace
wait(1)
local Part = game.Workspace:WaitForChild("EggCreator")
local EggTemplate = game.ReplicatedStorage:WaitForChild("Templates").EggTemplate
local function spawnEgg()
local placeholderParent = Instance.new("Part")
placeholderParent.Size = Vector3.new(2.26, 1.97, 2.06)
placeholderParent.Parent = workspace.EggFolder
placeholderParent.Transparency = 0
placeholderParent.Anchored = false
placeholderParent.Name = "EggKiller"
local random1 = math.random(-Part.Size.X,Part.Size.X)/2
local random2 = math.random(-Part.Size.Z,Part.Size.Z)/2
placeholderParent.Position = Part.Position+Vector3.new(random1,Part.Size.Y/2,random2)
local placeholder = Instance.new("SpecialMesh")
placeholder.Parent = placeholderParent
placeholder.Scale = Vector3.new(1,1,1)
placeholder.MeshId = "rbxassetid://379909978"
end
while wait(1) do
spawnEgg()
end
Now here is what I have currently that deletes that eggs that roll down the hill. (Which doesnt work.)
wait(1)
local DeleteEgg = game.Workspace.DeleteEggs
local Egg = game.Workspace.EggFolder.Egg
game.Workspace.DeleteEgg.Touched:Connect(function(partTouching)
if Egg == partTouching then
Egg.Remove()
end
end)
Now, first off. This doesnt work for one reason that I know, that the egg would only delete ONE egg, not all the eggs that spawn. This is because the script is not looping looking for new parts. (Like that I have in a script that kills the player with the egg).
Here is that by the way*
wait(1)
local folder = workspace.EggFolder
--local debounce = true
while true do
wait(1)
for _,v in pairs(folder:GetChildren()) do
if v:IsA('BasePart') then
v.Touched:Connect(function(touched)
--if debounce == true then
--debounce = false
local possibleHumanoid = touched.Parent:FindFirstChildWhichIsA('Humanoid')
if possibleHumanoid then
possibleHumanoid.Health = 0
v:Destroy()
end
---end
end)
end
end
end
How would I be able to prevent this from happening by changing the script that deletes it because the other scripts work perfectly!
I decided to make a rewrite of the kill script. Here you go:
local folder = workspace:WaitForChild("EggFolder")
folder.DescendantAdded:Connect(function(descendant)
if descendant:IsA("BasePart") then
descendant.Touched:Connect(function(touched)
local humanoid = touched.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid.Health = 0
descendant:Destroy()
end)
end
end)
And, for the other one, you used Egg.Remove(), which doesnât exist at all. Instead, use Egg:Destroy()
wait(1)
local DeleteEgg = game.Workspace.DeleteEggs
local Egg = game.Workspace.EggFolder.Egg
game.Workspace.DeleteEgg.Touched:Connect(function(partTouching)
if Egg == partTouching then
Egg:Destroy()
end
end)
Your script will only work for one egg. Try this instead:
local DeleteEgg = workspace:WaitForChild("DeleteEggs")
local EggFolder = workspace:WaitForChild("EggFolder")
game.Workspace.DeleteEgg.Touched:Connect(function(partTouching)
for _, Egg in pairs(EggFolder:GetChildren()) do
if Egg == partTouching then
Egg:Destroy()
end
end
end)
Edit: Yes, I had to edit the script since I made a string instead of a table in pairs().
local DeleteEgg = workspace:WaitForChild("DeleteEggs")
local EggFolder = workspace:WaitForChild("EggFolder")
DeleteEgg.DescendantAdded:Connect(function(descendant)
descendant.Touched:Connect(function(partTouching)
if table.find(EggFolder:GetChildren(), partTouching) then
partTouching:Destroy()
end
end)
end)
Note: Variable DeleteEgg must be a Folder or Model.
wait(1)
local DeleteEgg = game.Workspace.DeleteEggs
local Egg = game.Workspace.EggFolder.Egg
game.Workspace.DeleteEgg.Touched:Connect(function(partTouching)
if partTouching.Name == "--Part that you want it to touch name" then
Egg.Destroy()
end
end)
.Remove() does exist, itâs just that the syntax is not correct and Instance:Remove() is deprecated (but itâs not according to the object browser???)
wait(1)
local DeleteEgg = game.Workspace.DeleteEgg
local Egg = game.Workspace.EggFolder.Egg
DeleteEgg.Touched:Connect(function(touchedPart)
if touchedPart.Name == "Egg" then
touchedPart:Destroy()
end
end)
wait(1)
local DeleteEgg = game.Workspace.DeleteEggs
local Egg = game.Workspace.EggFolder.EggKiller
while true do
wait(1)
game.Workspace.DeleteEgg.Touched:Connect(function(partTouching)
if partTouching.Name == DeleteEgg then
Egg.Destroy()
end
end)
end
Got this error? The part is very clearly in there.
16:34:53.186 EggKiller is not a valid member of Folder âWorkspace.EggFolderâ - Server - RemoveEggs:3
16:34:53.186 Stack Begin - Studio
16:34:53.186 Script âServerScriptService.RemoveEggsâ, Line 3 - Studio - RemoveEggs:3
16:34:53.186 Stack End - Studio
You need to wait for the egg killer and since thereâs multiple egg killers:
workspace.EggFolder.ChildAdded:Connect(function(Egg)
Egg.Touched:Connect(function(partTouching)
if partTouching.Name == "DeleteEgg" then
Egg:Destroy()
end
end)
end)
I added this in, doesnt delete the parts but there is no error now.
wait(1)
local DeleteEgg = game.Workspace.DeleteEggs
while true do
wait(1)
workspace.EggFolder.ChildAdded:Connect(function(egg)
game.Workspace.EggFolder.EggKiller.Touched:Connect(function(partTouching)
if partTouching.Name == "DeleteEgg" then
game.Workspace.EggFolder.EggKiller:Destroy()
end
end)
end)
end
donât do that it will lag the game.
make your script just this:
workspace.EggFolder.ChildAdded:Connect(function(Egg)
Egg.Touched:Connect(function(partTouching)
if partTouching.Name == "DeleteEggs" then --Replace DeleteEggs with whatever the part to delete eggs is actually named.
Egg:Destroy()
end
end)
end)