Script tells me to get rid of end then wants me to add an end

I have a problem, its telling me to remove an end from my script, but when I do infact remove it, it wants me to add one.
Here’s the code.

 function CalculatePitch() --this returns the pitch that the engine should be at when its travelling
	return 1+engineBlock.Velocity.magnitude/10
	if engineBlock.Velocity.Magnitude > 1 then
		engineBlock.Starting.Volume = 3
	elseif engineBlock.Velocity.Magnitude < 1 then
		engineBlock.Starting.Volume = 0
	end
	end

In Luau and Lua 5.1, no statements after break, continue, and return inside a block is allowed. Your script places an if statement inside a function block after return. (Lua 5.2 and later is more lax, and allows statements after break inside a block)

2 Likes
function CalculatePitch() --this returns the pitch that the engine should be at when its travelling
	if engineBlock.Velocity.Magnitude > 1 then
		engineBlock.Starting.Volume = 3
	elseif engineBlock.Velocity.Magnitude < 1 then
		engineBlock.Starting.Volume = 0
	end
	return 1 + engineBlock.Velocity.magnitude / 10 -- Not sure if this should happen but if you put in a 'return' statement at the start of a script, it won't go to the next line of code!
end

This is an invalid syntax.

You do not need an extra closing parenthesis after a function end block.

2 Likes

Oh sorry! I didn’t know that! I will fix it!