part:Destroy() not working after using workspace:GetPartsInPart(part)

local RequestSlashPart = game.ReplicatedStorage.RequestSlashPart
RequestSlashPart.OnServerInvoke = function(player)
	local clone = workspace.GaruScript.Slash:Clone()
	clone.Parent = workspace
	
	local Character = player.Character or player.CharacterAdded:Wait()
	local clone2 = workspace.GaruScript.SlashBounds:Clone()
	clone2.CFrame =  Character.HumanoidRootPart.CFrame * CFrame.Angles(0,math.rad(90),0)
	clone2.Parent = workspace
	print("hello44")
	local debounceTable = {}
	for _, v in pairs(workspace:GetPartsInPart(clone2)) do
		print("hello47")
		if (game.Players:GetPlayerFromCharacter(v.Parent)) then
			return
		end
		local humanoid = v.Parent:FindFirstChild("Humanoid")
		if (humanoid and debounceTable[humanoid] ~= true) then
			debounceTable[humanoid] = true
			humanoid:TakeDamage(10)
		end
	end
	print("yeet")
	clone2:Destroy()
	print("yeeted")
end

I feel that the code is fairly self explanatory, if there is something you don’t get let me know. Clone2 is the part in question, slashbounds is a part with size 10,1,10 and cancollide off, anchored on. It is used to check if the slash part hits another humanoid.

yeet or yeeted never gets printed and clone2 doesn’t get destroyed. It stays there indefinitely and humanoids don’t get damaged.

hello(47) gets printed about 10 times if it hits an r15 rig, but only the first time i call this remote function. After that it might get printed once per time remote function is called.

Thats because theres a return exception. if v's parent is a player, then return. I believe you meant to use continue

1 Like

ok i copied this from another script i had that used .touched LMAO

thanks

1 Like

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