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

Lava script help?

Asked by 11 years ago
1Lava = game.Workspace.Lava
2 
3function onTouched(Lava)
4function PlayerWhoOnTouchedLava(game.Workspace:onTouched(Lava))
5    PlayerWhoOnTouchedLava.Humanoid = 0
6end
7end

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 11 years ago

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

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

Hope this helped!

Ad
Log in to vote
1
Answered by 11 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.

1function onTouched(part)
2human = part.Parent:findFirstChild("Humanoid") --Finds the humanoid of the part that touched
3if (human ~= nil) then --If humanoid does exist
4human.Health = 0 --Sets health at 0, causing death
5end
6end --You need and end for the function, and another end for the if statement.
7 
8script.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 11 years ago

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

Answer this question