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
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.
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!