Right now I have the model generated and spawned with a script. I’m debating if I should have the delete thingy in said script, or if I should just have a separate script inside of the model that does the deleting. I also only want the deletion of other models to happen one time right after the model is spawned. Heres the script so far, everything before the ChosenRoom.Touched:Connect line works perfectly, after that I just started freestyling.
local LargeUpperCoverStructure = game.ReplicatedStorage:WaitForChild("generatedLargeUpperCoverStructure"):GetChildren()
local goodparts = game.Workspace.Terrain:GetChildren()
for i, placeHolder2 in pairs (game.Workspace.PlaceHolder2:GetChildren()) do
local chosenRoom = LargeUpperCoverStructure[math.random(1,#LargeUpperCoverStructure)]:Clone()
chosenRoom.PrimaryPart = chosenRoom.Cover
chosenRoom:SetPrimaryPartCFrame(placeHolder2.CFrame)
chosenRoom.Parent = game.Workspace
chosenRoom.PrimaryPart:Destroy()
chosenRoom.Touched:Connect(function(hit) if hit.name ~= goodparts then BasePart.parent:Destroy()
end
2 right now, one that generates small stuff and one that generates big stuff. I want to make it so that the big stuff deletes all of the small stuff that it touches, but not the terrain that its on, nor anything else that touches it after it deletes all of the small stuff that touched it
Alright, sounds good how would I write the script? And well, I do want the deletion to only happen at the start of a round when a new map is being generated. I dont want players or vehicles touching the model and getting deleted during a round.
You may be able to get this to work out. This needs to be on a part that touches things.
Be nice if it didn’t touch anything else however … So looks like your back to the thing that gets touched.
local part = script.Parent
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Marked") then
hit:Destroy()
end
end)
Now we can get tricky … add a bool element named Marked only on the ones you wish to be destroyed. (most any element would work, we are just looking for the name to be Marked.
As long as anything touching that part don’t have a part in it named Marked you should be fine.
Things are touching each other all the time in a game.
Sorry for the 2 week long response, I had gotten busy with some other things.
I first attempted your solution, putting an invisible and none colliding part around all of the big structures, and then putting your script into said part while putting a script into all of the small structures named “marked”. This did not work.
What I ended up doing was editing my small structure generator script so that any small structure that spawns that touched the invisible part around all of the big structures would be deleted.
local UpperCover = game.ReplicatedStorage:WaitForChild("generated Upper Cover"):GetChildren()
for i, placeHolder2 in pairs (game.Workspace.PlaceHolder2:GetChildren()) do
local chosenRoom = UpperCover[math.random(1,#UpperCover)]:Clone()
chosenRoom.PrimaryPart = chosenRoom.Cover
chosenRoom:SetPrimaryPartCFrame(placeHolder2.CFrame)
chosenRoom.Parent = game.Workspace
for i,v in pairs(chosenRoom.Cover:GetTouchingParts()) do
if v.Name == "deleter" then
chosenRoom:Destroy()
break
end
end
end