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:
script.Parent.Baseplate.Touched:connect(function(hit) hit.Parent:FindFirstChild("Humanoid") hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10 end end)
Can anyone fix this?
I've also tried
hit.Parent.Humanoid:TakeDamge(10)
instead of
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:
--If this is the standard baseplate in workspace then you could do: --workspace:FindFirstChild("Baseplate") or workspace.Baseplate --I'm just showing you here how you could index a child using FindFirstChild local part = script.Parent:FindFirstChild("Baseplate") --You only have one function here. Make sure it has an end! --Since this is an anonymous function a closing ')' will follow the end part.Touched:Connect(function(hit) --Use capital Connect over connect when connecting functions if hit.Parent:FindFirstChild("Humanoid") then hit.Parent:FindFirstChild("Humanoid"):TakeDamage(10) end end)
edit: formatting. made stuff better.