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

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

Asked by 5 years ago

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.

0
i think one of your ends might be wrong. maybe try adding a ) to the first end ScrubSadmir 200 — 5y
0
I also tried that, also the first end isn't for a function, it's to find the child. DbExpress 20 — 5y
0
FindFirstChild doesn't need an end. You use it to get a child of some instance so set that line to a variable. xPolarium 1388 — 5y
0
mmm DaCrazyDev 444 — 5y

1 answer

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

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

2
its not really the answer, just remove the FindFirstChild, the original script have 1 extra end and this will give a nil error Leamir 3138 — 5y
1
true proIua 32 — 5y
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. xPolarium 1388 — 5y
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. xPolarium 1388 — 5y
0
Use a variable. You are repeating yourself in your code. User#21908 42 — 5y
Ad

Answer this question