Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago

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

head = game.Players.LocalPlayer.Character.Head

head:touched(part)
    part:destroy
end
0
how are you negative in reputation and you have to add () after destroy Osamiku 12 — 4y
0
Edited my post namespace25 594 — 4y
0
alr thx Donald_TrumpREAL1238 -27 — 4y
0
It will work with any named part. Test it out for yourself. namespace25 594 — 4y
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. namespace25 594 — 4y

2 answers

Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

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

0
attemp to index nil with IsA idk, but it did work thanks Donald_TrumpREAL1238 -27 — 4y
0
This is very inefficient. Not an answer worth accepting. namespace25 594 — 4y
Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

0
how do i make it like destroy any block it touches with the head. that is what im asking Donald_TrumpREAL1238 -27 — 4y
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 Donald_TrumpREAL1238 -27 — 4y
0
Hit doesn't refer to a name it refers to a game object. namespace25 594 — 4y
0
And BasePart is a class not a name namespace25 594 — 4y
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 Donald_TrumpREAL1238 -27 — 4y

Answer this question