Expected 'then' when parsing if statement, got '='


Try rewriting line 249 like so:

if (player:GetRankInGroup(GroupID) >= MinRank) or (player:GetRankInGroup(GroupId) == 12) or admins[player] then

However, something tells me this won’t fix it. There’s some part of your code where there is a stray β€œ=” that hasn’t been attended to. An incomplete variable/property assignment? A comparison that’s missing an extra =? Try looking for a red underline somewhere in your code.

I tried that, but it came with this error.



I tried looking for any errors in the script, no errors

you’re missing a keyword (end, then, if).

Most likely an end.

If you post the whole code I can see what you are missing.

my guy, I can’t read 500 lines of unformatted code.

put it in a code block

-- Settings

local GroupID = 1180042					-- Your group's GroupID
local MinRank = 18						-- Minimum rank needed for admin

--[[ 

β–ˆβ–ˆβ•—    β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— 
β–ˆβ–ˆβ•‘    β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β• 
β–ˆβ–ˆβ•‘ β–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘
β•šβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•
 β•šβ•β•β•β•šβ•β•β• β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•β•β•β•šβ•β•β•šβ•β•  β•šβ•β•β•β• β•šβ•β•β•β•β•β• 
                                                          
DO NOT TOUCH ANYTHING BELOW OR ELSE YOU RISK BREAKING THE SCRIPT.  
       
By Nullcaster
Additions and edits by Styxling

]]

-- Services
local DataStoreService = game:GetService('DataStoreService')
local TeleportService = game:FindService('TeleportService')
local ChatService = require(game:FindService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local Players = game:FindService('Players')
local MessagingService = game:GetService('MessagingService')
local GroupService = game:GetService('GroupService')

-- Datastore
local datastore = DataStoreService:GetGlobalDataStore()

-- Variables
local code, retrievingCode
local pendingQueue = {}
local admins = {}
local groups = {}
local MyGroupData = GroupService:GetGroupInfoAsync(GroupID)
local GroupName = MyGroupData.Name


-- Setup Chat Speaker
if not ChatService:GetChannel("All") then
	while true do
		local ChannelName = ChatService.ChannelAdded:Wait()
		if ChannelName == "All" then
			break
		end
	end
end

local speaker = ChatService:AddSpeaker("HUB")
speaker:JoinChannel("All")
speaker:SetExtraData("NameColor", Color3.fromRGB(255, 255, 255))
speaker:SetExtraData("ChatColor", Color3.fromRGB(186, 0, 0))

-- Functions
local function getAccessCode()
	local success, accessCode = pcall(function() 
		-- There is no need to add an error check here since, it does not matter if a new access code is created.
		return datastore:GetAsync("ReservedServer") 
	end)

	if not success or type(accessCode) ~= "string" then
		xpcall(function()
			accessCode = TeleportService:ReserveServer(game.PlaceId)
		end, function(message)
			speaker:SayMessage("Unable to reserve a server.", "All")
		end)

		if accessCode then
			local writeSuccess do
				local tries = 0

				repeat
					writeSuccess = pcall(function()
						datastore:SetAsync("ReservedServer", accessCode)
					end)

					-- Prevents Datastore Limitations of 6 seconds per request.
					if not writeSuccess then
						wait(6)
						tries = tries + 1
					end
				until writeSuccess or tries >= 5
			end

			if not writeSuccess then
				speaker:SayMessage("Unable to access reserved server. You will be unable to join the server.", "All")
			else
				speaker:SayMessage("Pending Hub successfully created a new server.", "All")
			end
		end
	else
		speaker:SayMessage("Pending Hub loaded successfully.", "All")
	end

	return accessCode
end

local function teleport(players)
	local tries = 0
	local teleportSuccess
	repeat
		teleportSuccess = pcall(function()
			TeleportService:TeleportToPrivateServer(game.PlaceId, code, players)
		end)

		if not teleportSuccess then
			wait(1)
			tries = tries + 1
		end
	until teleportSuccess or tries >= 8

	if not teleportSuccess then
		speaker:SayMessage("Unable to teleport players to private server.", "All")
	end
end









local function handleJoinRequest(func, identifier, accept, admin)
	--if #pendingQueue < 1 then return end
	identifier = string.lower(identifier)
	local publishSuccess, publishResult
	local tries = 0
	local t, user, id = nil

	local SayIt = ""

	if accept then
		SayIt = "been accepted"
	else
		SayIt = "been denied"
	end

	if func == "player" then
		--[[for i=1, #pendingQueue do
			if string.sub(string.lower(pendingQueue[i][1]), 1, string.len(identifier)) == identifier then
				user = pendingQueue[i][1]
				id = pendingQueue[i][2]
				t = i
				break
			end
		end]]
		for username, data in pairs(pendingQueue) do
			if string.sub(username, 1, string.len(identifier)) == identifier then
				user = username
				id = data[1]
				break
			end
		end

		if user then
			SayIt = user.." has "..SayIt
		else
			SayIt = nil
		end
	elseif func == "all" then
		user = "reset-queue"
		id = "handle-all"

		SayIt = "All penders have "..SayIt
	elseif func == "first" then

		local tyme = time()

		for username, data in pairs(pendingQueue) do
			if data[2] < tyme then
				user = username
				id = data[1]
				tyme = data[2]
			end
		end

		if user then
			SayIt = user.." (longest pender) has "..SayIt
		else
			SayIt = nil
		end
	elseif func == "last" then

		local tyme = 0

		for username, data in pairs(pendingQueue) do
			if data[2] > tyme then
				user = username
				id = data[1]
				tyme = data[2]
			end
		end

		if user then
			SayIt = user.." (newest pender) has "..SayIt
		else
			SayIt = nil
		end
	end

	if (user and id) then

		if user == "reset-queue" then
			pendingQueue = {}
		else
			--table.remove(pendingQueue, t)
			pendingQueue[user] = nil
		end

		repeat
			wait()
			publishSuccess, publishResult = pcall(function()
				MessagingService:PublishAsync("HandleJoinRequest", {id, accept, func})
			end)

			if not publishSuccess then
				tries = tries + 1
			end
		until publishSuccess or tries >= 8

		if func == "first" or func == "last" then
			speaker:SetExtraData("Tags", {{TagText = "+", TagColor = Color3.fromRGB(150, 150, 150)}})
			speaker:SayMessage(SayIt, "All")
			speaker:SetExtraData("Tags", {})
		end
	end
end

function pconcat(tab, sep)
	local ctab, n = {}, 1
	for i, v in pairs(tab) do
		ctab[n] = i
		n = n + 1
	end
	return table.concat(ctab, sep)
end

-- Main Script

function NewPlayer(player)
	-- Ignore Reserved Server
	if game.PrivateServerId ~= "" and game.PrivateServerOwnerId == 0 then
		player.Chatted:Connect(function(message)
			if (player:GetRankInGroup(GroupID) >= MinRank) or (player:GetRankInGroup(GroupID) == 12) or admins[player] then
				message = string.lower(message)
				local prefixMatch = string.match(message, "^!")

				if prefixMatch then
					message = string.gsub(message, prefixMatch, "", 1)
					local arguments = {}

					for argument in string.gmatch(message,"[^%s]+") do
						table.insert(arguments, string.lower(argument))
					end

					if arguments[1] == "accept" or arguments[1] == "decline" then
						local accept = arguments[1] == "accept"
						handleJoinRequest("player", arguments[2], accept, player.Name)
					elseif arguments[1] == "accept.all" or arguments[1] == "decline.all" then
						local accept = arguments[1] == "accept.all"
						handleJoinRequest("all", "", accept, player.Name)
					elseif arguments[1] == "accept.oldest" or arguments[1] == "accept.first" then
						handleJoinRequest("first", "", true, player.Name)
					elseif arguments[1] == "accept.new" or arguments[1] == "accept.newest" or arguments[1] == "accept.last" then
						handleJoinRequest("last", "", true, player.Name)	
					elseif arguments[1] == "add" or arguments[1] == "remove" then
						local identifier = arguments[2]
						local players = Players:GetPlayers()
						local target = nil
						for _, player in pairs(players) do
							if string.sub(player.Name, 1, string.len(identifier)) == identifier then
								target = player
								break
							end
						end

						if target and not (target:GetRankInGroup(GroupID) >= MinRank) then
							local value = arguments[1] == "add" or nil

							admins[target] = value
							local message = value and "%s added permissions to %s" or "%s removed permissions from %s"
							wait()
							local str = string.format(message, player.Name, target.Name)
							speaker:SayMessage(str, "All")
						end
					elseif arguments[1] == "addgroup" or arguments[1] == "removegroup" or arguments[1] == "setgroups" then
						local newgroups = {}
						if arguments[1] == "setgroups" then
							groups = {}
						end
						local value = (arguments[1] == "addgroup" or arguments[1] == "setgroups") or nil
						for idx = #arguments, 2, -1 do
							local id = tonumber(arguments[idx])
							local success, groupInfo = pcall(function() return GroupService:GetGroupInfoAsync(id) end)

							if success then
								groups[groupInfo.Name] = value
							end

							newgroups[groupInfo.Name] = true
						end

						local str = ""
						if arguments[1] == "setgroups" then
							str = player.Name..string.format(" set groups to: %s", pconcat(groups, ", "))
						elseif arguments[1] == "addgroup" then
							str = player.Name..string.format(" added groups: %s", pconcat(newgroups, ", "))
						elseif arguments[1] == "removegroup" then
							str = player.Name..string.format(" removed groups: %s", pconcat(newgroups, ", "))
						else
							str = player.Name.." | SetGroupsFunctionError"
						end
						speaker:SayMessage(str, "All")
					end
				end
			end
		end)

		return
	end

	-- Yields until an access code is generated or loaded.
	if not code and not retrievingCode then
		retrievingCode = true
		code = getAccessCode()
		retrievingCode = false
	elseif retrievingCode then
		repeat
			wait(1)
		until retrievingCode
	end

	-- Handle Teleportation and MessagingService
	if code then
		if player:GetRankInGroup(GroupID) >= MinRank or player:GetRankInGroup(GroupID) == 12 then
			teleport({player})

			local LastPend = 0

			player.Chatted:Connect(function(message)
				message = string.lower(message)
				local prefixMatch = string.match(message, "^!")

				if prefixMatch then
					message = string.gsub(message, prefixMatch, "", 1)
					local arguments = {}

					for argument in string.gmatch(message,"[^%s]+") do
						table.insert(arguments, string.lower(argument))
					end

					if arguments[1] == "pend" then
						if time() - LastPend < 20 then
							LastPend = time()
							MessagingService:PublishAsync("JoinRequest", {player.UserId, player.Name, player:GetRoleInGroup(GroupID)})
						end	
					elseif arguments[1] == "teleport" or arguments[1] == "tp" then
						teleport({player})
					end
				end
			end)

		else
			wait(1)
			if player and player.Parent then
				MessagingService:PublishAsync("JoinRequest", {player.UserId, player.Name, player:GetRoleInGroup(GroupID)})
			end
		end
	end
end

function PlayerLeaving(player)
	if game.PrivateServerId == "" then
		MessagingService:PublishAsync("PlayerLeaving", {player.UserId, player.Name})
	end	
end

Plrs = game.Players:GetChildren()
for i=1, #Plrs do
	NewPlayer(Plrs[i])
end
Players.PlayerAdded:Connect(NewPlayer)
Players.PlayerRemoving:Connect(PlayerLeaving)

if game.PrivateServerId == "" then -- PUBLIC SERVER
	MessagingService:SubscribeAsync("HandleJoinRequest", function(message)
		local data = message.Data

		local playerId = data[1]
		local accept = data[2]
		local func = data[3]

		if playerId == "handle-all" then
			local players = Players:GetPlayers()
			if accept then
				teleport(players)
			else
				for _, player in pairs(players) do
					player:Kick("You were declined from entering the server")
				end
			end
		else
			local target do
				for _, plr in pairs(Players:GetPlayers()) do
					if plr.UserId == playerId then
						target = plr
						break
					end
				end
			end

			if target then
				if accept then
					teleport({target})
				else
					target:Kick("You were declined from entering the server")
				end
			end
		end
	end)
elseif game.PrivateServerId ~= "" and game.PrivateServerOwnerId == 0 then -- PRIVATE SERVER
	MessagingService:SubscribeAsync("JoinRequest", function(message)
		local data = message.Data

		local playerId = data[1]
		local username = data[2]
		local role = data[3]

		if role == "?" or role == "" then
			local userGroups = GroupService:GetGroupsAsync(playerId)
			for _, groupInfo in pairs(userGroups) do
				if groups[groupInfo.Name] then
					role = groupInfo.Name
				end
			end
		end

		speaker:SetExtraData("Tags", {{TagText = role, TagColor = Color3.fromRGB(203, 0, 0)}})
		local str = string.format("%s is requesting to join the server.", username)
		speaker:SayMessage(str, "All")
		speaker:SetExtraData("Tags", {})

		--table.insert(pendingQueue, 1, {username, playerId})
		pendingQueue[string.lower(username)] = {playerId, time()}
	end)
	
	MessagingService:SubscribeAsync("PlayerLeaving", function(message)
		local data = message.Data

		local playerId = data[1]
		local username = data[2]

		pendingQueue[string.lower(username)] = nil
	end)

end

There are no compiler errors in this code, if there was it would show up with a red underline under it.

Are you sure you sent the right code? or are you running a modified version of what you sent?

1 Like

Yes, this is the correct code and the same code I modified.

1 Like

Well I can’t help you then, maybe you are looking at the wrong script. Is this script called β€œPendingHub” and is it the only one with that name parented to workspace?

1 Like

I would start by re-organising your code. All that nesting of if, elseif etc make the code really hard to read and debug. You also have a lot of code that is repeated in blocks, put any if block that repeats code or is more than a couple of lines of code into a function. That will make it a lot easier to figure out the problem. As it is you are asking us to spend a lot of time searching through the code to find a problem that would be more easily found if the code was bettter organised.

Like @batteryday I can’t see anything obvious wrong with the code, but it is hard to follow it as is, especially with all those anonymous/inline functions.

1 Like
local groupRank = player:GetRankInGroup(GroupID)
local isAdmin = admins[player]
if (groupRank >= MinRank or groupRank == 12) or isAdmin then

Try this change.

1 Like