I'm trying GetTouchingParts but it's not working

for count = 1, 25, 1 do
    script.Parent.indicate.Transparency = script.Parent.indicate.Transparency - 0.04
    if count == 25 then
        local target = script.Parent.damage:GetTouchingParts()
        print(target)
        print("boom")
        script.Parent:Destroy()
    else
        wait(0.04)
    end
end

even I touched damage part it still says like this also target[1] is still nil
(here is output)
{}
boom

What’s wrong and how can I fix this?

1 Like

Quick reminder to save you from getting your post taken down, put this in the #help-and-feedback:scripting-support category.

Also, your code is unreadable.
Use backticks at beginning and end of your code and reformat it.

Sense I have no clue what is going on I’ll just point things out.

K you fixed that;

A lot doesn’t really seem to add up, i don’t think somethings are even code. I’m really confused.
Any errors in the output?

1 Like

there was no error. I don’t know why but I can’t get parts.

So you’re damaging the parent of the script, then finding the touching parts of the damage??

This code doesn’t really make sense. If you want to put all the touching parts into a list, just type:

local targets = script.Parent:GetTouchingParts()

As for the damaging, you can use a for loop to damage all touching parts, like this:

for i,v in pairs(targets) do
     if v.Parent:FindFirstChild("Humanoid") ~= nil then
          v.Parent:TakeDamage(5) -- Change depending on how much you want to damage the players touching the part.
     end
end

Hopefully this is what you need, if it’s something different, just let me know.

The output is, “{}” because the part isn’t touching anything.

I don’t really understand what you want either.

If you want a damage part, you can use this.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent:BreakJoints()
	end
end)

Edit: I think I know what you mean.

script.Parent.Touched:Connect(function(hit)
	print("hello")
	if hit.Parent:FindFirstChild("Humanoid") then
		local Targets = script.Parent:GetTouchingParts()
		for i, v in pairs(Targets) do
			print(Targets)
		end
		hit.Parent:BreakJoints()
	end
end)

@Eattato_HACKED2

Hope this helps.