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

Stuck on a Lava Script - Help Please? [Unsolved]

Asked by 10 years ago

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:

1function onTouch(part)

I haven't found an error there, but it did nothing. Here's another part:

1local humanoid = findFirstChild("Player")

The third part is where I'd assume that I messed up. I'd need a developer to help me here:

1if (humanoid ~onTouch) then
2    humanoid.health~(-25)

And finally, incase you need it, here's the last part:

1    end
2        end
3script.Parent.Touched:connect(onTouch)

The sum of it all is this:

1function 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
7script.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.

3 answers

Log in to vote
0
Answered by 10 years ago

Ok, let's review your current script:

1function onTouch(part) --Correct
2local humanoid = findFirstChild("Player") --What is 'Player'? And you did not call 'FindFirstChild' right
3if (humanoid ~onTouch) then -- ERROR: Not a valid type of coding
4humanoid.health~(-25) --ERROR: Not a valid type of coding
5end --Correct
6end --Correct
7script.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;

01local debounce = false --We'll use debounce, to keep the code from firing multiple times
02 
03local function Lava(hit)
04if 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
05debounce = true --This'll keep the code from firing multiple times at once
06hit.Parent.Humanoid:TakeDamage(25) --This will damage the Humanoid if the requirements are found
07wait(1) --Waits 1 second
08debounce = false --Player can now use the thing again
09end --This ends the code block for the 'if' statement
10end --This ends the code block for the function 'Lava'
11 
12script.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!

0
Exactily what I was looking for. Deep explanations and correct coding. Thank you so much and thank you everyone who posted. JustGimmeDaBux 18 — 10y
0
No problem man. :) Glad to help. ;D TheeDeathCaster 2368 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Revamed script:

1function 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
6end
7 
8script.Parent.Touched:connect(onTouch)
0
Doesn't work. I can walk right over it in Solo player, and multiplayer mode. Any other ideas? JustGimmeDaBux 18 — 10y
0
Try that one epicfatcookie 0 — 10y
0
It works, but since it's a Lava Jump course, so I need -25 points every time they hit a single brick. Thanks for your help, and I accept your answer, but additional help would be excellent. Tyvm. JustGimmeDaBux 18 — 10y
Log in to vote
0
Answered by 10 years ago

Where is my side:

1function 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
6end
7 
8script.Parent.Touched:connect(onTouch)

Answer this question