How to make deadly instance part

Hello!
I wondered how to make an instance part deadly? Can you tell me? Thanks in advance.
P.S i using instance.new() for create parts
Bye :wave:

Can you elaborate more on a “deadly” part?

If you mean parts that kill you when you touch, then the wiki has everything you need.

Are you referring to a part that when you touch it, it kills you? You can try the following. There are more efficient ways to do this by the way, but this should give you a general understanding on what to do. This would work on a basic level.

local Part = workspace.TheNameOfThePart

Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
		hit.Parent.Humanoid.Health = 0
	end
end)

If you wanted multiple parts (which I’d assume so if you’re making something like an obby) to do the following instead I would recommend using CollectionService, it’s much more efficient.

1 Like

This is a lava block, like in obby. Only it is created using instance.new()

1 Like

if it kills players upon touching it, then a simple .touched event and giving damage to the player who touched it should do well for you

Maybe I explained you incorrectly.

while wait(1) do
	Part=Instance.new("Part")
	Part.Name ="Da part"
	Part.Shape = Enum.PartType.Ball
	Part.Size = Vector3.new(4, 4, 4)
	Part.Position =Vector3.new(-6.399, 8.35, 10.623)
	Part.Parent = workspace.BALLS
	
end

I used lava script, but it doesn’t work.

Because you didnt make anything to damage any players who touched it, add a .touched event of it to a table of connections

1 Like

I connected my script and the @alphadoggy111 script. It worked.

local connections = {}

while task.wait(1) do
	Part=Instance.new("Part")
	Part.Name ="Da part"
	Part.Shape = Enum.PartType.Ball
	Part.Size = Vector3.new(4, 4, 4)
	Part.Position =Vector3.new(-6.399, 8.35, 10.623)
	Part.Parent = workspace.BALLS
	
    connections[Part] = Part.Touched:Connect(function(part)
        local char = part:FindFirstAncestorOfClass("Model")

        if char and char.Humanoid then
           char.Humanoid.Health = 0
        end
    end)
end
1 Like

Also i do question why your positioning every new part instance to the same place, which will cause more lag

I just had nothing to do)
Okay, I was just doing a thing for my game.

1 Like