Expected ( at x Line error

Hello again, I’m wanting to make it so that the rain droplets delete themselves after a specified time has passed, but I keep getting an ‘Expected ( to close ) at line 22, got eof’ error.
Here’s my code as it stands atm:

local Droplets = 0
local ground = game.Workspace.Ground

while true do
	local Rain = Instance.new ("Part")
	if Droplets >= 2000 then
		break
	end
	local RNGX = math.random(1,99)
	local RNGZ = math.random(1,163)
	Droplets = Droplets + 1
		Rain.Parent = game.Workspace
		Rain.Name = "RainDrop"
	Rain.Size = Vector3.new(.5,1.5,.5)
		Rain.Transparency = .5
		Rain.CanCollide = true
		Rain.BrickColor =  BrickColor.new("Electric blue")
		Rain.Anchored = false
	Rain.Position = Vector3.new(RNGX,13,RNGZ)
	Rain.Material = "SmoothPlastic"
	wait(1.5)
	ground.Touched:Connect(function(hit)
	if Rain then
		wait(2)
		Rain:Destroy()	
	end

Thanks in advance

2 Likes

You have two opening parentheses on the first line here, as is typical for a connected function. You don’t do end), though, so you just have a parenthesis that never closes. You’re also missing multiple ends.

3 Likes

I get an ‘Expected identifier when parsing expression’ error when I put ) on end

1 Like

That’s probably due to the other issue I mentioned, which is that you’re missing several ends.

3 Likes

I got this code w/o errors, but I’ve noticed that sometimes I have to put a ) in a spot that seems like it wouldn’t make sense in (in this case, line 28), is this usually a result of typing the code structure incorrectly or is it normal?

local Droplets = 0
local ground = game.Workspace.Ground

while true do
	local Rain = Instance.new ("Part")
	if Droplets >= 2000 then
		break
	end
	local RNGX = math.random(1,99)
	local RNGZ = math.random(1,163)
	Droplets = Droplets + 1
		Rain.Parent = game.Workspace
		Rain.Name = "RainDrop"
	Rain.Size = Vector3.new(.5,1.5,.5)
		Rain.Transparency = .5
		Rain.CanCollide = true
		Rain.BrickColor =  BrickColor.new("Electric blue")
		Rain.Anchored = false
	Rain.Position = Vector3.new(RNGX,13,RNGZ)
	Rain.Material = "SmoothPlastic"
	wait(1.5)
	ground.Touched:Connect(function(hit)
	if Rain then
		wait(2)
		Rain:Destroy()	
				end
			end	
		)
	end
1 Like

It’s not normal, normally it wouldn’t happen.

1 Like

Formatting is irrelevant in Lua, but it looks off because of your indentation. This is normal, but it can be simplified.

[quote=“iHaydenz, post:5, topic:758564”]

while true do
	local Rain = Instance.new ("Part")
	if Droplets >= 2000 then
		break
	end
	local RNGX = math.random(1,99)
	local RNGZ = math.random(1,163)
	Droplets = Droplets + 1
		Rain.Parent = game.Workspace
		Rain.Name = "RainDrop"
	Rain.Size = Vector3.new(.5,1.5,.5)
		Rain.Transparency = .5
		Rain.CanCollide = true
		Rain.BrickColor =  BrickColor.new("Electric blue")
		Rain.Anchored = false
	Rain.Position = Vector3.new(RNGX,13,RNGZ)
	Rain.Material = "SmoothPlastic"
	wait(1.5)
	ground.Touched:Connect(function(hit)
	    if Rain then
		    wait(2)
		    Rain:Destroy()	
		end
	end)
end

There are still problems, such as how you connect the ground event multiple times. Move ground.Touched and everything in it to above the while loop.

1 Like

Your code should be like this:

ground.Touched:Connect(function(hit)
    if Rain then
        wait(2)
        Rain:Destroy()	
    end
end)
2 Likes

Yeah, I did that earlier, but it gave me an error whenever I do that, usually an ‘expected’ or ‘identifier expected’ error

codeerror

1 Like

Then your problem must have been with different things, that you already fixed now.

1 Like

I went ahead and moved it, but I’m still getting the same type of error that I mentioned in my reply to Redstone.
codeerror1

1 Like

Show me the whole thing as it currently is

1 Like
local Droplets = 0
local ground = game.Workspace.Ground
ground.Touched:Connect(function(hit)
	if Rain then
		wait(.5)
		Rain:Destroy()	
	end)
while true do
	local Rain = Instance.new ("Part")
	local RNGX = math.random(1,99)
	local RNGZ = math.random(1,163)
	Droplets = Droplets + 1
		Rain.Parent = game.Workspace
		Rain.Name = "RainDrop"
	Rain.Size = Vector3.new(.5,1.5,.5)
		Rain.Transparency = .5
		Rain.CanCollide = true
		Rain.BrickColor =  BrickColor.new("Electric blue")
		Rain.Anchored = false
	Rain.Position = Vector3.new(RNGX,13,RNGZ)
	Rain.Material = "SmoothPlastic"
	wait()
	
end

Add one more end above end)
end) matches the Connect(function(hit), but you need an end to match the if Rain then.

ground.Touched:Connect(function(hit)
	if Rain then
		wait(.5)
		Rain:Destroy()
    end
end)

That returns no errors, but now it’s not destroying the part like it’s meant to. I tried making it a function and moving the variables for the rain and rain parent out of the while loop, but the output says that the property is locked and = to null. Before I did that though, I noticed that it now underlines ‘Rain’ as an unknown global in the ground.touched function.

Oh I see what you’re doing. Give this a go.

local Droplets = 0
local ground = game.Workspace.Ground
while true do
	local Rain = Instance.new ("Part")
	local RNGX = math.random(1,99)
	local RNGZ = math.random(1,163)
	Droplets = Droplets + 1
		Rain.Parent = game.Workspace
		Rain.Name = "RainDrop"
	Rain.Size = Vector3.new(.5,1.5,.5)
		Rain.Transparency = .5
		Rain.CanCollide = true
		Rain.BrickColor =  BrickColor.new("Electric blue")
		Rain.Anchored = false
	Rain.Position = Vector3.new(RNGX,13,RNGZ)
	Rain.Material = "SmoothPlastic"
	wait()
	Rain.Touched:Connect(function(hit)
        if hit == ground then Rain:Destroy() end
    end)
end
1 Like

Also, if it lags, set CanCollide to false and get rid of the Touched event. Let them fall through the map and disappear on their own.

I’m not a expert but maybe try this code instead of yours.

Ground.Touched:Connect(function(hit)
     if hit.Name == "Rain" or hit.Parent.Name == "Rain" then
      wait(2)
      Rain:Destroy()
    end
end)

But I think @JarodOfOrbiter’s code should be working right?
The problem was you forgot to add two ends. Right?

This is what the code should look like when I test it.

local Droplets = 0
local ground = game.Workspace.Ground
local Rain = Instance.new("Part")

while true do
local RNGX = math.random(1,99)
	local RNGZ = math.random(1,163)
	local Rain = Instance.new("Part")
	Droplets = Droplets + 1
	Rain.Parent = game.Workspace
	Rain.Name = "RainDrop"
	Rain.Size = Vector3.new(.5,1.5,.5)
	Rain.Transparency = .5
	Rain.CanCollide = true
		Rain.BrickColor =  BrickColor.new("Electric blue")
		Rain.Anchored = false
		Rain.Position = Vector3.new(RNGX,13,RNGZ)
		Rain.Material = "SmoothPlastic"
	wait()
end

 ground.Touched:Connect(function(hit)
	if Rain then
		wait(.5)
		Rain:Destroy()	
	end

It deletes now, but not instantly, it’s at a slow pace compared to the spawn rate, I’ll record the video real quick so I can show you.