So title explains it all thorougly, here is what i have.
head = game.Players.LocalPlayer.Character.Head
head:touched(part)
part:destroy
end
So title explains it all thorougly, here is what i have.
head = game.Players.LocalPlayer.Character.Head
head:touched(part)
part:destroy
end
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
attemp to index nil with IsA idk, but it did work thanks
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.
how do i make it like destroy any block it touches with the head. that is what im asking
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
Hit doesn't refer to a name it refers to a game object.
And BasePart is a class not a name
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.
5 comments
how are you negative in reputation and you have to add () after destroy
Edited my post
alr thx
It will work with any named part. Test it out for yourself.
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.