Why is this destroying every part instead of the parts in the folder?

I created a script that SHOULD only destroy things in the folder but it is destroying every part in the game. Here is the script:

local Folder = game.Workspace.TrashCollection
local playerInBoat = false
local player = workspace.YellowBoat.Drive.Occupant
	if workspace.YellowBoat.Drive.Occupant then

		playerInBoat = true

local trashcollector = workspace.YellowBoat.Boat.TrashCollectors
	if hit.Parent == Folder and hit:IsA("Model") or hit:IsA("BasePart") and playerInBoat then
		if playerInBoat == true then
		game.Players:GetPlayerFromCharacter(workspace.YellowBoat.Drive.Occupant.Parent).leaderstats.Trash.Value += 1

I think it could be because of the “or” here, try to change that line with :
if hit.Parent == Folder and hit:IsA(“Model”) or hit.Parent == Folder and hit:IsA(“BasePart”) and playerInBoat then

1 Like

Now it is not destroying any of the parts.

Touched will never a return an object that isn’t a BasePart, so the hit:IsA("Model") (and BasePart check) is pointless.

if hit.Parent == Folder and playerInBoat then

Perhaps you meant to check if the trash was a descendant of the folder, and if the part was in a Model?

if hit:IsDescendantOf(Folder) and hit.Parent:IsA("Model") and playerInBoat then
1 Like

Thank you so much! It worked, I will mark this as solution for other people!

1 Like