Here is my script:
--Welcome to neopy2's script warning it may not work. -- the part is named murder because it murders you function onTouch(kill) game.workspace.murder end
if game.workspace.murder = kill then game.players.huminoid.health = 0
end--This should kill the player if they touch this brick
keep in mind I just started scripting.
You should use functions, I will script and explain each line to tell you how to do that
game.Workspace .murder.Touched:connect(function() -- REMMEMBER, Lua is case sensitive, workspace is Captial W And you must spell Murder correctly this will make a function when the brick is touched if hit,Parent:FindFirstChild("Humanoid") ~= nil then -- Will look for the humanoid in the parent of the thing that hit the brick hit.Parent.Humanoid.Health = 0 -- Will turn the humanoids health end end) -- Ends function
First of all, edit your answer so that your code is in a Code Block, that will make it a lot easier to read.
Secondly, there are several things wrong with your code.
The first problem is that you end the onTouch function before you actually do anything in it. Another problem would be that you have (kill) in the parentheses next to onTouch, when it should be (player) as that targets the player.
You state the Hierarchy game.workspace.murder but do nothing with it, so nothing would happen. You would have to give it something to do, or do something to it.
I'm going to basically write you a new code, and explain why it works over yours in comments.
--First off, try putting this in a LocalScript, as I prefer LocalPlayer. local Player = game.Players.LocalPlayer --Sets the Player variables to LocalPlayer, which works in Local Scripts. It targets the player. function onTouch() --You didn't need "kill" in the parentheses. Player.Character:WaitForChild("Humanoid").Health = 0 --Wait until the Humanoid is loaded, and sets the Health to 0. end --Your if statement was a decent shot, but "murder" is a part, and parts cannot have values. script.Parent.Touched:connect(onTouched) --This makes sure that when the parent of the script, in this case the "murder" brick, will run the function "onTouched" when the brick is touched.
As long as you put the script inside the murder brick, the script should function fine.
A few pointers: -Make sure your spelling and capitalization is correct, as this is key for scripts to function properly. -Make sure you don't end functions before the events you want to happen in the function occur.
I would suggest the Wiki for beginners to learn the basics of scripting.
I hope this helped!