My functions keep giving me errors

Every single time that I write a function, I get a syntax error. I keep getting expected ‘)’ to close ‘(’ at (line 5).

players.PlayerAdded:Connect(function(plr)
stage.Touched:connect(function(hit)

Can someone please help me?

local ObbyStages = workspace:WaitForChild(“ObbyStages”)

for _,stage in pairs(ObbyStages:GetChildren()) do

stage.Touched:connect(function(hit)
	
	local hum
	
	if hit.Parent:FindFirstChild("Humanoid") then
		
		hum = hit.Parent.Humanoid
		
		end
		
		if hit.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
			hum = hit.Parent.Parent.Humanoid
			
	end
	
	if hum then local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
		
		local plrstage = plr.leaderstats.Stage.Value
		
		if tonumber(stage.Name) == plrStage + 1 then
			
			plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
			
			elseif tonumber(stage.Name) > plrStage + 1 then
				
				hum.Health = 0
				
			end
		end
		
	end
1 Like

Can you show us the entire script?

1 Like

connect is deprecated, use Connect. Why is Can someome please help me? in the script? This can be the script:

players.PlayerAdded:Connect(function(plr)
stage.Touched:Connect(function(hit)

--Can someone please help me?

local ObbyStages = workspace:WaitForChild(“ObbyStages”)

for _,stage in pairs(ObbyStages:GetChildren()) do

stage.Touched:connect(function(hit)
	
	local hum
	
	if hit.Parent:FindFirstChild("Humanoid") then
		
		hum = hit.Parent.Humanoid
		
		end
		
		if hit.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
			hum = hit.Parent.Parent.Humanoid
			
	end
	
	if hum then local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
		
		local plrstage = plr.leaderstats.Stage.Value
		
		if tonumber(stage.Name) == plrStage + 1 then
			
			plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
			
			elseif tonumber(stage.Name) > plrStage + 1 then
				
				hum.Health = 0
				
			end
		end
		
	end
end)
end)
end)

That was not in the script. I had pasted the script into this thread I had forgot to leave a bit of space.

Can you give then the exact script? You said this is your script:

players.PlayerAdded:Connect(function(plr)
stage.Touched:connect(function(hit)

Can someone please help me?

local ObbyStages = workspace:WaitForChild(“ObbyStages”)

for _,stage in pairs(ObbyStages:GetChildren()) do

stage.Touched:connect(function(hit)
	
	local hum
	
	if hit.Parent:FindFirstChild("Humanoid") then
		
		hum = hit.Parent.Humanoid
		
		end
		
		if hit.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
			hum = hit.Parent.Parent.Humanoid
			
	end
	
	if hum then local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
		
		local plrstage = plr.leaderstats.Stage.Value
		
		if tonumber(stage.Name) == plrStage + 1 then
			
			plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
			
			elseif tonumber(stage.Name) > plrStage + 1 then
				
				hum.Health = 0
				
			end
		end
		
	end

players.PlayerAdded:Connect(function(plr)
stage.Touched:Connect(function(hit)

local ObbyStages = workspace:WaitForChild(“ObbyStages”)

for _,stage in pairs(ObbyStages:GetChildren()) do

stage.Touched:connect(function(hit)

local hum



if hit.Parent:FindFirstChild("Humanoid") then
	
	hum = hit.Parent.Humanoid
	
	end
	
	if hit.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
		hum = hit.Parent.Parent.Humanoid
		
end

if hum then local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
	
	local plrstage = plr.leaderstats.Stage.Value
	
	if tonumber(stage.Name) == plrStage + 1 then
		
		plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
		
		elseif tonumber(stage.Name) > plrStage + 1 then
			
			hum.Health = 0
			
		end
	end
	
end

end)
end)
end)

local ObbyStages = workspace:WaitForChild(“ObbyStages”)
for _,stage in pairs(ObbyStages:GetChildren()) do
stage.Touched:connect(function(hit)

     local hum

     if hit.Parent:FindFirstChild("Humanoid") then
	
	hum = hit.Parent.Humanoid
	
	end
	
	if hit.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
		hum = hit.Parent.Parent.Humanoid
		
end)

if hum then local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
	
	local plrstage = plr.leaderstats.Stage.Value
	
	if tonumber(stage.Name) == plrStage + 1 then
		
		plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
		
		elseif tonumber(stage.Name) > plrStage + 1 then
			
			hum.Health = 0
			
		end
	end)
	
end)

Please format your code properly (put ``` before and after your code). It’s hard to follow what’s going on, but it seems like you’re missing a parenthesis somewhere, based on the error. Remember to indent, since it makes these kinds of issues easier to spot.

2 Likes

Oops my bad. I am just promoted to member here lol.

1 Like