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

Lava script help?

Asked by 10 years ago
Lava = game.Workspace.Lava 

function onTouched(Lava)
function PlayerWhoOnTouchedLava(game.Workspace:onTouched(Lava))
    PlayerWhoOnTouchedLava.Humanoid = 0
end
end

When you step on the brick, you die. But it won't do that. The funcion PlayerWhoOnTouchedLava() is the person who touched lava, It won't work. Why?

3 answers

Log in to vote
2
Answered by 10 years ago

Well first off, there are many errors in your script. This would be the correct way of writing it:

local Lava = game.Workspace.Lava
function onTouched(Obj) --The function that gets called when Lava is touched
    if Obj.Parent:FindFirstChild("Humanoid") then --Checks to make sure there is a humanoid
        Obj.Parent.Humanoid.Health = 0 --Makes the health of that humanoid 0
    end
end
Lava.Touched:connect(onTouched) --connects the Touched event to the onTouched function

Hope this helped!

Ad
Log in to vote
1
Answered by 10 years ago

You set 'Lava' as a parameter, and parameters only apply to the function in which they are given in. Thus, meaning, your variable is nil. Best way to do this is by checking for the part's humanoid that touched the brick.

function onTouched(part)
human = part.Parent:findFirstChild("Humanoid") --Finds the humanoid of the part that touched
if (human ~= nil) then --If humanoid does exist
human.Health = 0 --Sets health at 0, causing death
end
end --You need and end for the function, and another end for the if statement.

script.Parent.Touched:connect(onTouched) --Connection line

If you have any other problems, feel free to inbox me.

~Kyo-Chan

Log in to vote
1
Answered by 10 years ago

When I saw PlayerWhoOnTouchedLava, then a second function straight after it. I lol'd XD

Answer this question