Unable to cast array ban system

I was making a ban system for my game when I encountered a error.
“Unable to Cast Array: Line 29”

Code

		plr.Chatted:Connect(function(msg)
			local args = msg:split(" ")
			if args[1] == ":ban" then
				if args[2] then
					if not game:GetService("Players"):FindFirstChild(args[2]) then return end
					local reason = table.concat(args, " ", 3)
					local user = game:GetService("Players"):FindFirstChild(args[2])
					if not args[3] or args[3] == "" then return reason == "no reason provided" end
					--[[line 29]] BanDatastore:SetAsync(user.UserId.."-banTutorial",plr.Name,reason)
					user:Kick("You have been banned. Rejoin to get more information about this punishment.")
				end
			end
		end)
	end
end)
1 Like

The problem is caused because of you trying to pass 3 arguments. Store the playerName and reason in a table and it should resolve it:

local banInfo = {
	plrName = "",
	reason = ""
}

		plr.Chatted:Connect(function(msg)
			local args = msg:split(" ")
			if args[1] == ":ban" then
				if args[2] then
					if not game:GetService("Players"):FindFirstChild(args[2]) then return end
					local reason = table.concat(args, " ", 3)
					local user = game:GetService("Players"):FindFirstChild(args[2])
					if not args[3] or args[3] == "" then return reason == "no reason provided" end
					banInfo["plrName"] = plr.Name
					banInfo["reason"] = reason
					--[[line 29]] BanDatastore:SetAsync(user.UserId.."-banTutorial",data)
					user:Kick("You have been banned. Rejoin to get more information about this punishment.")
				end
			end
		end)
	end
end)
1 Like

Did this fix your problem?

1 Like