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.
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!
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)
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)