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

How come this script is not working?

Asked by
neopy2 0
10 years ago

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.

0
it is supposed to look neater neopy2 0 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

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

0
I reccomend you to watch Friaza's videos, and use the wiki to learn. it's simple if you get the hang of it. PlatinumLocks 50 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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!

Answer this question