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:

function onTouch(part)

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

    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:

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

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

    end
        end 
script.Parent.Touched:connect(onTouch)

The sum of it all is this:

function onTouch(part) 
    local humanoid = findFirstChild("Player")
    if (humanoid ~onTouch) then
        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...
    end
        end 
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.

3 answers

Log in to vote
0
Answered by 10 years ago

Ok, let's review your current script:

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

local debounce = false --We'll use debounce, to keep the code from firing multiple times

local function Lava(hit)
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
debounce = true --This'll keep the code from firing multiple times at once
hit.Parent.Humanoid:TakeDamage(25) --This will damage the Humanoid if the requirements are found
wait(1) --Waits 1 second
debounce = false --Player can now use the thing again
end --This ends the code block for the 'if' statement
end --This ends the code block for the function 'Lava'

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!

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:

function onTouch(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    if (humanoid ~= nil) then
        humanoid.Health = 75 -- Predicting that robloxians have 100 health and when they touch this it negatives by 25
    end
end

script.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:

function onTouch(part) 
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    if (humanoid ~= nil) then   -- if a humanoid exists, then
        humanoid.Health = 25    -- damage the humanoid
    end 
end

script.Parent.Touched:connect(onTouch)

Answer this question