Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make it when my head touches a block it deletes the block?

So title explains it all thorougly, here is what i have.

head = game.Players.LocalPlayer.Character.Head

head:touched(part)
	part:destroy
end

5 comments

0

how are you negative in reputation and you have to add () after destroy

0

Edited my post

0

alr thx

0

It will work with any named part. Test it out for yourself.

0

The answer you accepted is in efficient and he clearly doesn't know what he's doing. Anything that touches the head even if not a part will be destroyed. My answer did the exact same thing his did but actually worked.

2 answers

✓ Accepted answer

try this

local Player = game.Players.LocalPlayer
Player.Character.Head.Touched:Connect(function(obj)
	if hit:IsA("BasePart") then
		obj:Destroy()
	end
end)

and you can put this script automatically in a players head by using

local ReplicatedStorage = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(plr)
	local script = ReplicatedStorage.script:Clone() -- replace .script with the name of the script
	script.Parent = plr.Charatcer.Head
end)

make sure to put the top script in replicated storage and the bottom one in serverscriptservice This will destroy any object the players head touches with the class BasePart

2 comments

0

attemp to index nil with IsA idk, but it did work thanks

0

This is very inefficient. Not an answer worth accepting.

Simple answer: BasePart.Touched.

Lemme explain.

part.Touched:Connect(function(hit)
	if hit:IsA("BasePart") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
	
		if player then
			if hit.Name == "Head" then
				part:Destroy()
			end
		end
	end
end)

This works by using what's called the Touched event. It uses a base part(part, mesh, union, etc) and when something else touches it it fires our function. The hit argument is what touched it. Here we check if it's a real player and if it is we destroy it.

5 comments

0

how do i make it like destroy any block it touches with the head. that is what im asking

0

part.Touched:Connect(function(hit) where is the part coming from not everything is named part, like any block it touches regards of the name of it just the type

0

Hit doesn't refer to a name it refers to a game object.

0

And BasePart is a class not a name

0

the script works but how could i make it destroy anything with the class basepart lets say it doesnt matter what the name is

This discussion is preserved as it was. New answers, comments, and votes are closed.