I tried to make a successful lava script where when you touch it, it damages a user 25 HP. I tried to make it, and it just won't kill a user.
Here is the script I started with, before it got more complex:
1 | function onTouch(part) |
I haven't found an error there, but it did nothing. Here's another part:
1 | local humanoid = findFirstChild( "Player" ) |
The third part is where I'd assume that I messed up. I'd need a developer to help me here:
1 | if (humanoid ~onTouch) then |
2 | humanoid.health~(- 25 ) |
And finally, incase you need it, here's the last part:
1 | end |
2 | end |
3 | script.Parent.Touched:connect(onTouch) |
The sum of it all is this:
1 | function onTouch(part) |
2 | local humanoid = findFirstChild( "Player" ) |
3 | if (humanoid ~onTouch) then |
4 | humanoid.health~(- 25 ) --The '25' there is a negative number to show the loss of 25 Health Points, however it may be impossible to add into a script... |
5 | end |
6 | end |
7 | script.Parent.Touched:connect(onTouch) |
If I can get the script to be correct and damage the user, that would be great. It just doesn't work for me, and I'd like some help. Thank you for your time.
Ok, let's review your current script:
1 | function onTouch(part) --Correct |
2 | local humanoid = findFirstChild( "Player" ) --What is 'Player'? And you did not call 'FindFirstChild' right |
3 | if (humanoid ~onTouch) then -- ERROR: Not a valid type of coding |
4 | humanoid.health~(- 25 ) --ERROR: Not a valid type of coding |
5 | end --Correct |
6 | end --Correct |
7 | script.Parent.Touched:connect(onTouch) --Correct |
Overall, there are three errors in your script; You did not call FindFirstChild
correctly, you did not do the 'if' statement correctly; if humanoid ~ onTouch [Ehm, what? Just a '~'?]
wouldn't you mean if humanoid ~= nil [as allot of people use]
you are attempting to compare humanoid
to the function, thus an error, lastly you did not damage the Humanoid, and misspelled Health
; humanoid.Health = humanoid.Health - 25
, all of these were your errors, also, you did not add a Debounce
to keep the function from firing multiple times at once.
Let's remake your script;
01 | local debounce = false --We'll use debounce, to keep the code from firing multiple times |
02 |
03 | local function Lava(hit) |
04 | if hit.Parent and hit.Parent:FindFirstChild( "Humanoid" ) and not debounce then --This will check to see if hit.Parent, and Humanoid exists within hit.Parent 'hit.Parent is the instance that touched the Part', also to check 'debounce' to see if it is false |
05 | debounce = true --This'll keep the code from firing multiple times at once |
06 | hit.Parent.Humanoid:TakeDamage( 25 ) --This will damage the Humanoid if the requirements are found |
07 | wait( 1 ) --Waits 1 second |
08 | debounce = false --Player can now use the thing again |
09 | end --This ends the code block for the 'if' statement |
10 | end --This ends the code block for the function 'Lava' |
11 |
12 | script.Parent.Touched:connect(Lava) --Now, whenever the Part [if inside a Part] is touched, it'll fire the '.Touched' event, that which will run the 'Lava' function |
Hope this helped!
Revamed script:
1 | function onTouch(part) |
2 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
3 | if (humanoid ~ = nil ) then |
4 | humanoid.Health = 75 -- Predicting that robloxians have 100 health and when they touch this it negatives by 25 |
5 | end |
6 | end |
7 |
8 | script.Parent.Touched:connect(onTouch) |
Where is my side:
1 | function onTouch(part) |
2 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
3 | if (humanoid ~ = nil ) then -- if a humanoid exists, then |
4 | humanoid.Health = 25 -- damage the humanoid |
5 | end |
6 | end |
7 |
8 | script.Parent.Touched:connect(onTouch) |