Lua help needed

Hello,

I’m trying to learn lua while making a server, and now I’m stuck at a small config file for a plugin called timerewards.
It would be really helpful if someone could help me solve this error.

I’m trying to add a bypass for all already higher ranks, so the people with the higher ranks don’t get downgraded to that rank.

This is the code in the state I have it now:


local blacklist_ranks = { "admin", "superadmin" }



TimeRewards:Add( {
	RankName = "Regular",
	TimeRequire = { days = 0, hours = 4, mins = 0 },
	Reward = function( ply )
			
	if table.HasValue( blacklist_ranks, ply:GetNWString("usergroup") ) then
	ply:ChatPrint( "You already have a higher rank" )
	else
		
	ply:ChatPrint( "You are now a regular on the server, thank you!" )
		
	 ply:addMoney( 5000 )
	 ply:ChatPrint( "You were rewared €5000 for achieving the Regular rank!" )
	 ply:SetNWString( "usergroup", "regular" )
	 end
} )

This gives me the error that there is a unexpected symbol near the last “}”.

In this state the code will work:



TimeRewards:Add( {
	RankName = "Regular",
	TimeRequire = { days = 0, hours = 4, mins = 0 },
	Reward = function( ply )
	ply:ChatPrint( "You are now a regular on the server, thank you!" )
	ply:addMoney( 5000 )
	ply:ChatPrint( "You were rewared €5000 for achieving the Regular rank!" )
	ply:SetNWString( "usergroup", "regular" )
	end
} )

The instructions from the addon maker (who is not responding to my questions):
“To stop it from rewarding if you are a certain rank, add this local blacklist_ranks = { “admin”, “superadmin” } if ( table.HasValue( blacklist_ranks, ply:GetNWString(“usergroup”) ) then return end That would go above the promoting code, so this would be inside the top of the reward function.”

Thanks a lot for reading and helping me out!

try putting it on one line.

Could you give me an example?

It doesn’t need to be on one line.

The problem is that you have only one end. You need to close the if statement AND the function.

When I close the “if” statement its expecting to end the function near “else” too

[lua]
function name()

if (something) then

end – always needs to be here

if (something_else) then

else

end – always needs to be here

end – always needs to be here
[/lua]

[editline]14th April 2016[/editline]

[lua]
TimeRewards:Add( {
RankName = “Regular”,
TimeRequire = { days = 0, hours = 4, mins = 0 },
Reward = function( ply )

if table.HasValue( blacklist_ranks, ply:GetNWString("usergroup") ) then
ply:ChatPrint( "You already have a higher rank" )
else
	
ply:ChatPrint( "You are now a regular on the server, thank you!" )
	
 ply:addMoney( 5000 )
 ply:ChatPrint( "You were rewared €5000 for achieving the Regular rank!" )
 ply:SetNWString( "usergroup", "regular" )
 end
     end -- NEED THIS

} )
[/lua]

Try this:
local ply = LocalPlayer()
if (!ply:IsUserGroup(“admin”) or !ply:IsUserGroup(“superadmin”) or !ply:IsUserGroup(“owner”) then
TimeRewards:Add( {
RankName = “Regular”,
TimeRequire = { days = 0, hours = 4, mins = 0 },
Reward = function( ply )
ply:ChatPrint( “You are now a regular on the server, thank you!” )
ply:addMoney( 5000 )
ply:ChatPrint( “You were rewared €5000 for achieving the Regular rank!” )
ply:SetNWString( “usergroup”, “regular” )
end
end
} )

That fixed it for me! Lua is sometimes very confusing for me, sorry if it was a dumb question.

Thanks a lot for your help!

Nvm I c u got it :stuck_out_tongue:

You should use tables, they’re nice.