There's an error in my script " Workspace.Script:5: ')' expected (to close '(' at line 1) near 'end' " And this is the script I used:
1 | script.Parent.Baseplate.Touched:connect( function (hit) |
2 | hit.Parent:FindFirstChild( "Humanoid" ) |
3 | hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10 |
4 | end |
5 | end ) |
Can anyone fix this?
I've also tried
1 | hit.Parent.Humanoid:TakeDamge( 10 ) |
instead of
1 | hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10 |
But it still wouldn't work.
:FindFirstChild() is used to get the child of some instance and you can set it to a variable.
With this you can simply the code and even use :TakeDamage() instead.
This would look like:
01 | --If this is the standard baseplate in workspace then you could do: |
02 | --workspace:FindFirstChild("Baseplate") or workspace.Baseplate |
03 |
04 | --I'm just showing you here how you could index a child using FindFirstChild |
05 | local part = script.Parent:FindFirstChild( "Baseplate" ) |
06 |
07 | --You only have one function here. Make sure it has an end! |
08 | --Since this is an anonymous function a closing ')' will follow the end |
09 | part.Touched:Connect( function (hit) |
10 | --Use capital Connect over connect when connecting functions |
11 |
12 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
13 | hit.Parent:FindFirstChild( "Humanoid" ):TakeDamage( 10 ) |
14 | end |
15 | end ) |
edit: formatting. made stuff better.