Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Workspace.Script:5: ')' expected (to close '(' at line 1) near 'end'?

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.

4 comments

0

i think one of your ends might be wrong. maybe try adding a ) to the first end

0

I also tried that, also the first end isn't for a function, it's to find the child.

0

FindFirstChild doesn't need an end. You use it to get a child of some instance so set that line to a variable.

0

mmm

1 answer

: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.

5 comments

2

its not really the answer, just remove the FindFirstChild, the original script have 1 extra end and this will give a nil error

1

true

1

Where in this script would throw a nil error? The only way I would see it throwing one would be because another part that's not in the character model touches "baseplate". All you need to do for that is encompass lines 13-14 in an if-statement.

0

Changed the way the script worked. Before I had it to show OP other ways of going about his issue. Answering shouldn't just be a a working new script but one that also include other ways of going about it.

0

Use a variable. You are repeating yourself in your code.

This discussion is preserved as it was. New answers, comments, and votes are closed.