Hello, I'am new to scripting and I want to make this block be able to kill a player when it touches it. Is there a way to do this?
You can either just find the humanoid or find the humanoid and :GetPlayerFromCharacter()
. It all depends on what requirements you want the touched event to have. One basic way in writing this could be :
script.Parent.Touched:connect(function(hit) -- Assuming this script is in the block, server script. The "hit" is the parameter to connect the Touched event. local hum = hit.Parent:FindFirstChild("Humanoid") -- You don't put hit.Parent.Character because the hit.Parent is the character. You also find the humanoid because you will eventually be taking health off of the player and this is where the health resides. if hum ~= nil then --Scripters use this so we can check what is touching the brick is actually a humanoid, this way the script won't error or crash. hum.Health = hum.Health - 100 --This will instantly kill the player, you can adjust the amount of health you want taken off by changing the "100" to whatever you want. To be on the safe side though you could do "hit.Parent:BreakJoints()". This is a safer way because a person with admin might change their health to lets say "10000000000" and the script would only subtract a 100, resulting in them not dying. end end)
If this helped you please don't forget to give a thumbs up and accept the answer. If it errored or you have any questions please comment on my answer and I will be glad to help.
Try this:
script.Parent.Touched:connect(function(part) if part.Parent:FindFirstChild("Humanoid") then part.Parent.Humanoid.Health = 0 end end)