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

I am trying to make a deathblock script that only kills me when I touch it?

Asked by 3 years ago

I’m trying to learn scripting. It is very hard, and I tried to make this deathblock as a frist try. But something isn’t working as it should. I tried to make it so it only kills me when I touch it. I would be so thankful if someone is able to help me with my mistakes.

function kill(player)
    Player.Parent.Humanoid.Health = Player.Parent.Humanoid.Health == -100
    Script.Parent.Touched.Connect(kill)
end

2 answers

Log in to vote
2
Answered by
2_MMZ 1059 Moderation Voter
3 years ago

So what you need to do is get the Humanoid from the player that touches the brick.

function kill(player)

won't work. If you're going to kill the Humanoid, you must identify it. Here's a script that fixes your mistakes.

script.Parent.Touched:Connect(function(Hit)
if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = 0

Hope this helped you.

0
It did! Thank you. This defenently helped me with my scripting! :) DogPower05 0 — 3y
0
Nice, although I think the "and" isn't necessary to make a kill script. You can just use break joints. Nitrolux200 62 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

DeathBlock script [kills everyone that touches it]:

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

DeathBlock script [ONLY KILLS YOU!]


local Name = "PlayersUsername" -- This will be the only player that can die by touching the brick script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid.DisplayName == Name then humanoid.Health = 0 end end)

Hope this helped!

Answer this question